Inheritance: Dev2.Studio.ViewModels.WorkSurface.BaseWorkSurfaceViewModel, IHelpSource, IStudioTab
 public void SchedulerViewModel_AccountName_SetAccountName_IsDirty()
 {
     //------------Setup for test--------------------------
     var _accountNameChanged = false;
     Mock<IEventAggregator> eventAggregator = new Mock<IEventAggregator>();
     eventAggregator.Setup(c => c.Publish(It.IsAny<DebugOutputMessage>())).Verifiable();
     var schedulerViewModel = new SchedulerViewModel(eventAggregator.Object, new Mock<DirectoryObjectPickerDialog>().Object, new Mock<IPopupController>().Object, new TestAsyncWorker(), new Mock<IConnectControlViewModel>().Object);
     var scheduledResourceForTest = new ScheduledResourceForTest();
     schedulerViewModel.PropertyChanged += (sender, args) =>
     {
         if(args.PropertyName == "AccountName")
         {
             _accountNameChanged = true;
         }
     };
     schedulerViewModel.SelectedTask = scheduledResourceForTest;
     schedulerViewModel.ShowError("Error while saving: Logon failure: unknown user name or bad password");
     Assert.AreEqual("Error while saving: Logon failure: unknown user name or bad password", schedulerViewModel.Error);
     //------------Execute Test---------------------------
     schedulerViewModel.AccountName = "someAccountName";
     //------------Assert Results-------------------------
     Assert.AreEqual("", schedulerViewModel.Error);
     Assert.IsTrue(schedulerViewModel.SelectedTask.IsDirty);
     Assert.AreEqual("someAccountName", schedulerViewModel.SelectedTask.UserName);
     Assert.IsTrue(_accountNameChanged);
 }
示例#2
0
        internal SchedulerTaskManager(SchedulerViewModel schedulerViewModel, Task <IResourcePickerDialog> getResourcePicker)
        {
            _schedulerViewModel       = schedulerViewModel;
            _resourcePickerDialogTask = getResourcePicker;
            var taskServiceConvertorFactory = new TaskServiceConvertorFactory();

            SchedulerFactory = new ClientSchedulerFactory(new Dev2TaskService(taskServiceConvertorFactory), taskServiceConvertorFactory);
        }
        public void GivenHasAScheduleOf(string scheduleName, Table table)
        {
            AppSettings.LocalHost = "http://localhost:3142";
            SchedulerViewModel scheduler = new SchedulerViewModel(EventPublishers.Aggregator, new DirectoryObjectPickerDialog(), new PopupController(), new AsyncWorker(), new Mock<IConnectControlViewModel>().Object);
            IEnvironmentModel environmentModel = EnvironmentRepository.Instance.Source;

            environmentModel.Connect();
            scheduler.ScheduledResourceModel = new ClientScheduledResourceModel(environmentModel);
            scheduler.CurrentEnvironment = environmentModel;
            scheduler.CreateNewTask();
            scheduler.SelectedTask.Name = ScenarioContext.Current["ScheduleName"].ToString();
            scheduler.SelectedTask.OldName = "bob";
            scheduler.SelectedTask.UserName = ScenarioContext.Current["UserName"].ToString();
            scheduler.SelectedTask.Password = ScenarioContext.Current["Password"].ToString();
            scheduler.SelectedTask.WorkflowName = ScenarioContext.Current["WorkFlow"].ToString();
            scheduler.SelectedTask.NumberOfHistoryToKeep = (int)ScenarioContext.Current["HistoryCount"];
            scheduler.SelectedTask.Status = (SchedulerStatus)ScenarioContext.Current["TaskStatus"];
            scheduler.Errors.ClearErrors();
            var task = scheduler.SelectedTask;
            UpdateTrigger(task, table);

            PrivateObject po = new PrivateObject(scheduler.CurrentEnvironment);
            var mockAuth = new Mock<IAuthorizationService>();
            mockAuth.Setup(a => a.IsAuthorized(It.IsAny<AuthorizationContext>(), null)).Returns(true);
            po.SetFieldOrProperty("AuthorizationService", mockAuth.Object);
            ScenarioContext.Current["Scheduler"] = scheduler;
            try
            {
                scheduler.SaveCommand.Execute("");
            }
            catch(Exception e)
            {

                ScenarioContext.Current["Error"] = e.Message;
            }


        }
        public void SchedulerViewModel_AddWorkflow_WithNewTaskNameSet_WorkflowNameChangedAndNameChanged()
        {
            //------------Setup for test--------------------------
            var resources = new ObservableCollection<IScheduledResource> { new ScheduledResource("New Task1", SchedulerStatus.Enabled, DateTime.MaxValue, new Mock<IScheduleTrigger>().Object, "TestFlow1") { NumberOfHistoryToKeep = 1 } };
            var mockEnvironmentModel = new Mock<IEnvironmentModel>();
            var mockConnection = new Mock<IEnvironmentConnection>();
            mockConnection.Setup(connection => connection.IsConnected).Returns(true);
            mockConnection.Setup(connection => connection.WorkspaceID).Returns(Guid.NewGuid());
            mockEnvironmentModel.Setup(model => model.Connection).Returns(mockConnection.Object);
            mockEnvironmentModel.Setup(model => model.IsConnected).Returns(true);
            ResourceRepository resourceRepo = new ResourceRepository(mockEnvironmentModel.Object);
            var setupResourceModelMock = Dev2MockFactory.SetupResourceModelMock(ResourceType.WorkflowService, "TestFlow2");
            var resId = Guid.NewGuid();
            setupResourceModelMock.Setup(c => c.ID).Returns(resId);
            resourceRepo.Add(Dev2MockFactory.SetupResourceModelMock(ResourceType.WorkflowService, "TestFlow1").Object);
            resourceRepo.Add(setupResourceModelMock.Object);
            resourceRepo.Add(Dev2MockFactory.SetupResourceModelMock(ResourceType.WorkflowService, "TestFlow3").Object);
            mockEnvironmentModel.Setup(c => c.ResourceRepository).Returns(resourceRepo);

            var schedulerViewModel = new SchedulerViewModel(new Mock<IEventAggregator>().Object, new Mock<DirectoryObjectPickerDialog>().Object, new Mock<IPopupController>().Object, new TestAsyncWorker(), new Mock<IConnectControlViewModel>().Object) { CurrentEnvironment = mockEnvironmentModel.Object };
            Mock<IResourcePickerDialog> mockResourcePickerDialog = new Mock<IResourcePickerDialog>();
            mockResourcePickerDialog.Setup(c => c.ShowDialog(It.IsAny<IEnvironmentModel>())).Returns(true);
            mockResourcePickerDialog.Setup(c => c.SelectedResource).Returns(setupResourceModelMock.Object);

            schedulerViewModel.ResourcePickerDialog = mockResourcePickerDialog.Object;

            Mock<IScheduledResourceModel> scheduledResourceModelMock = new Mock<IScheduledResourceModel>();
            scheduledResourceModelMock.Setup(c => c.ScheduledResources).Returns(resources);
            schedulerViewModel.ScheduledResourceModel = scheduledResourceModelMock.Object;
            //------------Execute Test---------------------------
            schedulerViewModel.TaskList[0].WorkflowName = "TestFlow3";
            schedulerViewModel.SelectedTask = schedulerViewModel.TaskList[0];

            var _nameChange = false;
            var _workflowNameChange = false;
            var _taskListChange = false;

            schedulerViewModel.PropertyChanged += delegate(object sender, PropertyChangedEventArgs args)
            {
                switch(args.PropertyName)
                {
                    case "TaskList":
                        _taskListChange = true;
                        break;
                    case "Name":
                        _nameChange = true;
                        break;
                    case "WorkflowName":
                        _workflowNameChange = true;
                        break;
                }
            };

            schedulerViewModel.AddWorkflowCommand.Execute(null);
            //------------Assert Results-------------------------  
            Assert.IsTrue(_nameChange);
            Assert.IsTrue(_workflowNameChange);
            Assert.IsTrue(_taskListChange);
            Assert.IsTrue(schedulerViewModel.SelectedTask.IsDirty);
            Assert.AreEqual("TestFlow2", schedulerViewModel.Name);
            Assert.AreEqual("Category\\Testing", schedulerViewModel.WorkflowName);
            Assert.AreEqual(resId, schedulerViewModel.SelectedTask.ResourceId);
        }
示例#5
0
        public void MainViewModel_OnStudioClosing_ClosesRemoteEnvironmants()
        {
            //Barney, commented out when I removed the feedback stuff from the studio
            //SetupDefaultMef();
            var eventPublisher = new Mock<IEventAggregator>();
            var environmentRepository = new Mock<IEnvironmentRepository>();
            var connected1 = new Mock<IEnvironmentModel>();
            var connected2 = new Mock<IEnvironmentModel>();
            var notConnected = new Mock<IEnvironmentModel>();
            connected1.Setup(a => a.IsConnected).Returns(true).Verifiable();
            connected1.Setup(a => a.Disconnect()).Verifiable();
            connected2.Setup(a => a.IsConnected).Returns(true).Verifiable();
            connected2.Setup(a => a.Disconnect()).Verifiable();
            notConnected.Setup(a => a.IsConnected).Returns(false).Verifiable();
            IList<IEnvironmentModel> lst = new List<IEnvironmentModel> { connected1.Object, connected2.Object, notConnected.Object };

            environmentRepository.Setup(repo => repo.Source).Returns(new Mock<IEnvironmentModel>().Object);
            environmentRepository.Setup(repo => repo.All()).Returns(lst);
            var versionChecker = new Mock<IVersionChecker>();
            var asyncWorker = new Mock<IAsyncWorker>();
            asyncWorker.Setup(w => w.Start(It.IsAny<System.Action>(), It.IsAny<System.Action>())).Verifiable();
            var mvm = new MainViewModel(eventPublisher.Object, asyncWorker.Object, environmentRepository.Object, versionChecker.Object, false);
            var popup = new Mock<IPopupController>();
            popup.Setup(a => a.ShowSchedulerCloseConfirmation()).Returns(MessageBoxResult.Cancel).Verifiable();
            var scheduler = new SchedulerViewModel(EventPublishers.Aggregator, new DirectoryObjectPickerDialog(), popup.Object, new TestAsyncWorker(), new Mock<IConnectControlViewModel>().Object) { WorkSurfaceContext = WorkSurfaceContext.Scheduler };
            var task = new Mock<IScheduledResource>();
            task.Setup(a => a.IsDirty).Returns(false);
            scheduler.SelectedTask = task.Object;
            var vm = new WorkSurfaceContextViewModel(new EventAggregator(), new WorkSurfaceKey(), scheduler, new Mock<IPopupController>().Object, (a, b) => { });

            mvm.Items.Add(vm);
            Assert.IsTrue(mvm.OnStudioClosing());   // assert that the studio closes
            connected1.Verify(a => a.IsConnected);
            connected1.Verify(a => a.Disconnect());
            connected2.Verify(a => a.IsConnected);
            connected2.Verify(a => a.Disconnect());
            notConnected.Verify(a => a.IsConnected);

        }
        public void SchedulerViewModel_WorkflowName_BlankName_SetsError()
        {
            //------------Setup for test--------------------------

            var schedulerViewModel = new SchedulerViewModel(new Mock<IEventAggregator>().Object, new Mock<DirectoryObjectPickerDialog>().Object, new Mock<IPopupController>().Object, new TestAsyncWorker(), new Mock<IConnectControlViewModel>().Object);

            var scheduledResourceForTest = new ScheduledResourceForTest { WorkflowName = "Test" };
            schedulerViewModel.SelectedTask = scheduledResourceForTest;

            //------------Execute Test---------------------------
            schedulerViewModel.WorkflowName = "";
            //------------Assert Results-------------------------
            Assert.IsTrue(schedulerViewModel.HasErrors);
            Assert.AreEqual("Please select a workflow to schedule", schedulerViewModel.Error);
            Assert.AreEqual(string.Empty, schedulerViewModel.SelectedTask.WorkflowName);
            Assert.IsTrue(schedulerViewModel.SelectedTask.IsDirty);
        }
 public void SchedulerViewModel_SelectedHistory_SetSelectedHistory_DebugMessageFiredTwice()
 {
     //------------Setup for test--------------------------
     Mock<IEventAggregator> eventAggregator = new Mock<IEventAggregator>();
     eventAggregator.Setup(c => c.Publish(It.IsAny<DebugOutputMessage>())).Verifiable();
     var schedulerViewModel = new SchedulerViewModel(eventAggregator.Object, new Mock<DirectoryObjectPickerDialog>().Object, new Mock<IPopupController>().Object, new TestAsyncWorker(), new Mock<IConnectControlViewModel>().Object);
     var scheduledResourceForTest = new ScheduledResourceForTest();
     schedulerViewModel.SelectedTask = scheduledResourceForTest; //Fires DebugOutMessage for null SelectedHistory
     //------------Execute Test---------------------------
     schedulerViewModel.SelectedHistory = new ResourceHistoryForTest(); //Fires DebugOutMessage for set SelectedHistory
     //------------Assert Results-------------------------
     eventAggregator.Verify(c => c.Publish(It.IsAny<DebugOutputMessage>()), Times.Exactly(2));
 }
        public void SchedulerViewModel_SelectedTask_SetValue_ShouldFirePropertyChangedNotifications()
        {
            //------------Setup for test--------------------------
            var _selectedTaskChanged = false;
            var _triggerChange = false;
            var _statusChange = false;
            var _workflowNameChange = false;
            var _nameChange = false;
            var _runasapChange = false;
            var _numRecordsChange = false;
            var _triggerTextChange = false;
            var _historyMustChange = false;
            var _accountNameChange = false;
            var _passwordChange = false;
            var _errorsChange = false;
            var _errorChange = false;
            var _selectedHistoryChange = false;

            var agg = new Mock<IEventAggregator>();
            agg.Setup(a => a.Publish(It.IsAny<DebugOutputMessage>())).Verifiable();
            var schedulerViewModel = new SchedulerViewModel(agg.Object, new DirectoryObjectPickerDialog(), new PopupController(), new TestAsyncWorker(), new Mock<IConnectControlViewModel>().Object);


            schedulerViewModel.PropertyChanged += delegate(object sender, PropertyChangedEventArgs args)
            {
                switch(args.PropertyName)
                {
                    case "SelectedTask":
                        _selectedTaskChanged = true;
                        break;
                    case "Trigger":
                        _triggerChange = true;
                        break;
                    case "Status":
                        _statusChange = true;
                        break;
                    case "WorkflowName":
                        _workflowNameChange = true;
                        break;
                    case "Name":
                        _nameChange = true;
                        break;
                    case "RunAsapIfScheduleMissed":
                        _runasapChange = true;
                        break;
                    case "NumberOfRecordsToKeep":
                        _numRecordsChange = true;
                        break;
                    case "TriggerText":
                        _triggerTextChange = true;
                        break;
                    case "History":
                        _historyMustChange = true;
                        break;
                    case "AccountName":
                        _accountNameChange = true;
                        break;
                    case "Password":
                        _passwordChange = true;
                        break;
                    case "Errors":
                        _errorsChange = true;
                        break;
                    case "Error":
                        _errorChange = true;
                        break;
                    case "SelectedHistory":
                        _selectedHistoryChange = true;
                        break;
                }
            };
            //------------Execute Test---------------------------
            schedulerViewModel.SelectedTask = new ScheduledResourceForTest();
            //------------Assert Results-------------------------
            Assert.IsTrue(_selectedTaskChanged);
            Assert.IsTrue(_triggerChange);
            Assert.IsTrue(_statusChange);
            Assert.IsTrue(_workflowNameChange);
            Assert.IsTrue(_nameChange);
            Assert.IsTrue(_runasapChange);
            Assert.IsTrue(_numRecordsChange);
            Assert.IsTrue(_triggerTextChange);
            Assert.IsFalse(_historyMustChange);
            Assert.IsTrue(_accountNameChange);
            Assert.IsTrue(_passwordChange);
            Assert.IsTrue(_errorsChange);
            Assert.IsTrue(_errorChange);
            Assert.IsTrue(_selectedHistoryChange);
            agg.Verify(a => a.Publish(It.IsAny<DebugOutputMessage>()));
        }
        public void SchedulerViewModel_ClearError_WithNormalError_HasErrorsSet()
        {
            //------------Setup for test--------------------------
            var schedulerViewModel = new SchedulerViewModel(new Mock<IEventAggregator>().Object, new Mock<DirectoryObjectPickerDialog>().Object, new Mock<IPopupController>().Object, new TestAsyncWorker(), new Mock<IConnectControlViewModel>().Object) { SelectedTask = new ScheduledResourceForTest() };
            var _hasErrorChange = false;
            var _errorChange = false;

            schedulerViewModel.ShowError("test error");

            Assert.IsTrue(schedulerViewModel.HasErrors);

            schedulerViewModel.PropertyChanged += delegate(object sender, PropertyChangedEventArgs args)
            {
                switch(args.PropertyName)
                {
                    case "HasErrors":
                        _hasErrorChange = true;
                        break;
                    case "Error":
                        _errorChange = true;
                        break;
                }
            };

            //------------Execute Test---------------------------
            schedulerViewModel.ClearError("test error");
            //------------Assert Results-------------------------
            Assert.IsTrue(_hasErrorChange);
            Assert.IsTrue(_errorChange);
            Assert.IsFalse(schedulerViewModel.HasErrors);
        }
 public void SchedulerViewModel_NumberOfRecordsToKeep_SetNumberOfRecordsToKeep_IsDirtyTrue()
 {
     //------------Setup for test--------------------------
     var schedulerViewModel = new SchedulerViewModel(new Mock<IEventAggregator>().Object, new Mock<DirectoryObjectPickerDialog>().Object, new Mock<IPopupController>().Object, new TestAsyncWorker(), new Mock<IConnectControlViewModel>().Object);
     var scheduledResourceForTest = new ScheduledResourceForTest();
     schedulerViewModel.SelectedTask = scheduledResourceForTest;
     //------------Execute Test---------------------------
     Assert.IsFalse(schedulerViewModel.SelectedTask.IsDirty);
     schedulerViewModel.NumberOfRecordsToKeep = "10";
     //------------Assert Results-------------------------
     Assert.IsTrue(schedulerViewModel.SelectedTask.IsDirty);
 }
        public void SchedulerViewModel_Constructor_ValidConstruction_ShouldSetHelpText()
        {
            //------------Setup for test--------------------------

            //------------Execute Test---------------------------
            var schedulerViewModel = new SchedulerViewModel(new Mock<IEventAggregator>().Object, new Mock<DirectoryObjectPickerDialog>().Object, new Mock<IPopupController>().Object, new TestAsyncWorker(), new Mock<IConnectControlViewModel>().Object);

            //------------Assert Results-------------------------
            Assert.AreEqual(@"To schedule a workflow execution, setup the trigger you want to use  and the workflow you want to execute.
Warewolf leverages Windows Task Scheduler and the schedules can be viewed there as well.", schedulerViewModel.HelpText);
        }
        public void SchedulerViewModel_Validation_NoErrorsWhenNothingSelected()
        {
            var resourceModel = new Mock<IScheduledResourceModel>();
            var resources = new ObservableCollection<IScheduledResource> { new ScheduledResource("bob", SchedulerStatus.Enabled, DateTime.MaxValue, new Mock<IScheduleTrigger>().Object, "c"), new ScheduledResource("dave", SchedulerStatus.Enabled, DateTime.MaxValue, new Mock<IScheduleTrigger>().Object, "c") };
            resourceModel.Setup(a => a.ScheduledResources).Returns(resources);

            var schedulerViewModel = new SchedulerViewModel
            {
                ScheduledResourceModel = resourceModel.Object
            };
            Assert.IsFalse(schedulerViewModel.HasErrors);

        }
 public void SchedulerViewModel_History_Get_ShouldCallCreateHistoryOnScheduledResourceModel()
 {
     //------------Setup for test--------------------------
     var schedulerViewModel = new SchedulerViewModel(new Mock<IEventAggregator>().Object, new Mock<DirectoryObjectPickerDialog>().Object, new Mock<IPopupController>().Object, new TestAsyncWorker(), new Mock<IConnectControlViewModel>().Object);
     var activeItem = new TabItem { Header = "History" };
     schedulerViewModel.ActiveItem = activeItem;
     var mockScheduledResourceModel = new Mock<IScheduledResourceModel>();
     var histories = new List<IResourceHistory> { new Mock<IResourceHistory>().Object };
     mockScheduledResourceModel.Setup(model => model.CreateHistory(It.IsAny<IScheduledResource>())).Returns(histories);
     schedulerViewModel.ScheduledResourceModel = mockScheduledResourceModel.Object;
     schedulerViewModel.SelectedTask = new Mock<IScheduledResource>().Object;
     //------------Execute Test---------------------------
     var resourceHistories = schedulerViewModel.History;
     //------------Assert Results-------------------------
     mockScheduledResourceModel.Verify(model => model.CreateHistory(It.IsAny<IScheduledResource>()), Times.Once());
     Assert.IsNotNull(resourceHistories);
 }
 public void SchedulerViewModel_ActiveItem_HeaderHistory_ShouldFirePropertyChangeOnHistory()
 {
     //------------Setup for test--------------------------
     var _historyMustChange = false;
     var schedulerViewModel = new SchedulerViewModel();
     var activeItem = new TabItem { Header = "History" };
     schedulerViewModel.PropertyChanged += (sender, args) =>
     {
         if(args.PropertyName == "History")
         {
             _historyMustChange = true;
         }
     };
     //------------Execute Test---------------------------
     schedulerViewModel.ActiveItem = activeItem;
     //------------Assert Results-------------------------
     Assert.IsTrue(_historyMustChange);
 }
        public void SchedulerViewModel_NumberOfRecordsToKeep_NotWholeNumber_KeepsOldNumber()
        {
            //------------Setup for test--------------------------

            var resources = new ObservableCollection<IScheduledResource>();
            var scheduledResourceForTest = new ScheduledResourceForTest { Name = "Test" };
            var scheduledResourceForTest2 = new ScheduledResourceForTest { Name = "Test2" };
            scheduledResourceForTest.IsDirty = false;
            resources.Add(scheduledResourceForTest);
            resources.Add(scheduledResourceForTest2);
            var schedulerViewModel = new SchedulerViewModel();

            var mockScheduledResourceModel = new Mock<IScheduledResourceModel>();
            mockScheduledResourceModel.Setup(model => model.ScheduledResources).Returns(resources);
            schedulerViewModel.ScheduledResourceModel = mockScheduledResourceModel.Object;
            schedulerViewModel.SelectedTask = scheduledResourceForTest;
            //------------Execute Test---------------------------
            schedulerViewModel.NumberOfRecordsToKeep = "5";
            schedulerViewModel.NumberOfRecordsToKeep = "-a5";
            //------------Assert Results-------------------------
            Assert.AreEqual(5, schedulerViewModel.SelectedTask.NumberOfHistoryToKeep);
            Assert.IsTrue(schedulerViewModel.SelectedTask.IsDirty);
        }
        public void SchedulerViewModel_Name_NonDuplicateName_ClearsError()
        {
            //------------Setup for test--------------------------

            var resources = new ObservableCollection<IScheduledResource>();
            var scheduledResourceForTest = new ScheduledResourceForTest { Name = "Test" };
            var scheduledResourceForTest2 = new ScheduledResourceForTest { Name = "Test2" };
            scheduledResourceForTest.IsDirty = true;
            resources.Add(scheduledResourceForTest);
            resources.Add(scheduledResourceForTest2);
            var schedulerViewModel = new SchedulerViewModel();

            var mockScheduledResourceModel = new Mock<IScheduledResourceModel>();
            mockScheduledResourceModel.Setup(model => model.ScheduledResources).Returns(resources);
            schedulerViewModel.ScheduledResourceModel = mockScheduledResourceModel.Object;
            schedulerViewModel.SelectedTask = scheduledResourceForTest;
            schedulerViewModel.Name = "Test2";
            //------------Assert Preconditions------------------
            Assert.IsTrue(schedulerViewModel.HasErrors);
            Assert.AreEqual("There is already a task with the same name", schedulerViewModel.Error);
            Assert.AreEqual("Test2", schedulerViewModel.SelectedTask.Name);
            Assert.IsTrue(schedulerViewModel.SelectedTask.IsDirty);

            //------------Execute Test---------------------------
            schedulerViewModel.Name = "Test Some";
            //------------Assert Results-------------------------
            Assert.IsFalse(schedulerViewModel.HasErrors);
            Assert.AreEqual(string.Empty, schedulerViewModel.Error);
            Assert.AreEqual("Test Some", schedulerViewModel.SelectedTask.Name);
            Assert.IsTrue(schedulerViewModel.SelectedTask.IsDirty);

        }
        public void SchedulerViewModel_Constructor_ValidConstruction_ShouldSetProperties()
        {
            //------------Setup for test--------------------------

            //------------Execute Test---------------------------
            var schdulerViewModel = new SchedulerViewModel();
            //------------Assert Results-------------------------
            Assert.IsNotNull(schdulerViewModel);
            Assert.IsNotNull(schdulerViewModel.Errors);
        }
        public void SchedulerViewModel_DeActivateCancel_ReturnsFalse()
        {
            //------------Setup for test--------------------------
            var resources = new ObservableCollection<IScheduledResource>();
            var scheduledResourceForTest = new ScheduledResourceForTest { Trigger = new ScheduleTrigger(TaskState.Ready, new Dev2DailyTrigger(new TaskServiceConvertorFactory(), new DailyTrigger()), new Dev2TaskService(new TaskServiceConvertorFactory()), new TaskServiceConvertorFactory()), IsDirty = true };
            resources.Add(scheduledResourceForTest);
            Dev2JsonSerializer serializer = new Dev2JsonSerializer();
            var serializeObject = serializer.SerializeToBuilder(resources);
            var mockEnvironmentModel = new Mock<IEnvironmentModel>();
            var mockConnection = new Mock<IEnvironmentConnection>();
            mockConnection.Setup(connection => connection.IsConnected).Returns(true);
            mockConnection.Setup(connection => connection.ExecuteCommand(It.IsAny<StringBuilder>(), It.IsAny<Guid>())).Returns(serializeObject);
            mockConnection.Setup(connection => connection.WorkspaceID).Returns(Guid.NewGuid());
            mockEnvironmentModel.Setup(model => model.Connection).Returns(mockConnection.Object);
            mockEnvironmentModel.Setup(model => model.IsConnected).Returns(true);
            ResourceRepository resourceRepo = new ResourceRepository(mockEnvironmentModel.Object);
            var setupResourceModelMock = Dev2MockFactory.SetupResourceModelMock(ResourceType.WorkflowService, "TestFlow2");
            resourceRepo.Add(Dev2MockFactory.SetupResourceModelMock(ResourceType.WorkflowService, "TestFlow1").Object);
            resourceRepo.Add(setupResourceModelMock.Object);
            resourceRepo.Add(Dev2MockFactory.SetupResourceModelMock(ResourceType.WorkflowService, "TestFlow3").Object);
            mockEnvironmentModel.Setup(c => c.ResourceRepository).Returns(resourceRepo);
            var popup = new Mock<IPopupController>();
            popup.Setup(a => a.ShowSchedulerCloseConfirmation()).Returns(MessageBoxResult.Cancel);
            var schedulerViewModel = new SchedulerViewModel(new Mock<IEventAggregator>().Object, new Mock<DirectoryObjectPickerDialog>().Object, popup.Object, new TestAsyncWorker(), new Mock<IConnectControlViewModel>().Object) { SelectedTask = scheduledResourceForTest, CurrentEnvironment = null };
            //------------Execute Test---------------------------
            Assert.IsFalse(schedulerViewModel.DoDeactivate());
            //------------Assert Results-------------------------

        }
        public void SchedulerViewModel_Validation_NoErrorOnSelected()
        {
            var resourceModel = new Mock<IScheduledResourceModel>();
            var resources = new ObservableCollection<IScheduledResource> { new ScheduledResource("bob", SchedulerStatus.Enabled, DateTime.MaxValue, new Mock<IScheduleTrigger>().Object, "c"), new ScheduledResource("dave", SchedulerStatus.Enabled, DateTime.MaxValue, new Mock<IScheduleTrigger>().Object, "c") };
            resourceModel.Setup(a => a.ScheduledResources).Returns(resources);

            var schedulerViewModel = new SchedulerViewModel
                {
                    ScheduledResourceModel = resourceModel.Object,
                    SelectedTask = resources[0],
                    Name = "monkeys"
                };
            // validation occurs on property changes
            Assert.IsFalse(schedulerViewModel.HasErrors);

        }
        public void SchedulerViewModel_DeActivateSave_AttemptsSave()
        {
            //------------Setup for test--------------------------
            var resources = new ObservableCollection<IScheduledResource>();
            var scheduledResourceForTest = new ScheduledResourceForTest { Trigger = new ScheduleTrigger(TaskState.Ready, new Dev2DailyTrigger(new TaskServiceConvertorFactory(), new DailyTrigger()), new Dev2TaskService(new TaskServiceConvertorFactory()), new TaskServiceConvertorFactory()), IsDirty = true };
            resources.Add(scheduledResourceForTest);
            Dev2JsonSerializer serializer = new Dev2JsonSerializer();
            var serializeObject = serializer.SerializeToBuilder(resources);
            var mockEnvironmentModel = new Mock<IEnvironmentModel>();
            var mockConnection = new Mock<IEnvironmentConnection>();
            mockConnection.Setup(connection => connection.IsConnected).Returns(true);
            mockConnection.Setup(connection => connection.ExecuteCommand(It.IsAny<StringBuilder>(), It.IsAny<Guid>())).Returns(serializeObject);
            mockConnection.Setup(connection => connection.WorkspaceID).Returns(Guid.NewGuid());
            mockEnvironmentModel.Setup(model => model.Connection).Returns(mockConnection.Object);
            mockEnvironmentModel.Setup(model => model.IsConnected).Returns(true);
            ResourceRepository resourceRepo = new ResourceRepository(mockEnvironmentModel.Object);
            var setupResourceModelMock = Dev2MockFactory.SetupResourceModelMock(ResourceType.WorkflowService, "TestFlow2");
            resourceRepo.Add(Dev2MockFactory.SetupResourceModelMock(ResourceType.WorkflowService, "TestFlow1").Object);
            resourceRepo.Add(setupResourceModelMock.Object);
            resourceRepo.Add(Dev2MockFactory.SetupResourceModelMock(ResourceType.WorkflowService, "TestFlow3").Object);
            mockEnvironmentModel.Setup(c => c.ResourceRepository).Returns(resourceRepo);
            var popup = new Mock<IPopupController>();
            popup.Setup(a => a.ShowSchedulerCloseConfirmation()).Returns(MessageBoxResult.Yes);
            var schedulerViewModel = new SchedulerViewModel(new Mock<IEventAggregator>().Object, new Mock<DirectoryObjectPickerDialog>().Object, popup.Object, new TestAsyncWorker(), new Mock<IConnectControlViewModel>().Object) { SelectedTask = scheduledResourceForTest };

            var auth = new Mock<IAuthorizationService>();
            mockEnvironmentModel.Setup(a => a.AuthorizationService).Returns(auth.Object);
            auth.Setup(a => a.IsAuthorized(AuthorizationContext.Administrator, null)).Returns(false).Verifiable();
            schedulerViewModel.CurrentEnvironment = mockEnvironmentModel.Object;
            //------------Execute Test---------------------------
            schedulerViewModel.DoDeactivate();
            //------------Assert Results-------------------------
            auth.Verify(a => a.IsAuthorized(AuthorizationContext.Administrator, null));
            Assert.AreEqual(@"Error while saving: You don't have permission to schedule on this server.
You need Administrator permission.", schedulerViewModel.Error);



        }
        public void SchedulerViewModel_Validation_IfDuplicateNames()
        {
            var resourceModel = new Mock<IScheduledResourceModel>();
            var resources = new ObservableCollection<IScheduledResource> { new ScheduledResource("bob", SchedulerStatus.Enabled, DateTime.MaxValue, new Mock<IScheduleTrigger>().Object, "c") { NumberOfHistoryToKeep = 1 }, new ScheduledResource("dave", SchedulerStatus.Enabled, DateTime.MaxValue, new Mock<IScheduleTrigger>().Object, "c") };
            resourceModel.Setup(a => a.ScheduledResources).Returns(resources);

            var schedulerViewModel = new SchedulerViewModel
                {
                    ScheduledResourceModel = resourceModel.Object,
                    SelectedTask = resources[0],
                    Name = "dave"
                };
            //create duplicate name
            Assert.IsTrue(schedulerViewModel.HasErrors);
            Assert.AreEqual("There is already a task with the same name", schedulerViewModel.Error);
            Assert.IsTrue(resources.All(a => a.Errors.HasErrors()));
            Assert.IsTrue(resources.All(a => a.Errors.FetchErrors()[0] == "There is already a task with the same name"));


        }
 public void SchedulerViewModel_Trigger_SetTrigger_IsDirtyTrue()
 {
     //------------Setup for test--------------------------
     var schedulerViewModel = new SchedulerViewModel(new Mock<IEventAggregator>().Object, new Mock<DirectoryObjectPickerDialog>().Object, new Mock<IPopupController>().Object, new TestAsyncWorker(), new Mock<IConnectControlViewModel>().Object);
     var scheduledResourceForTest = new ScheduledResourceForTest();
     schedulerViewModel.SelectedTask = scheduledResourceForTest;
     //------------Execute Test---------------------------
     Assert.IsFalse(schedulerViewModel.SelectedTask.IsDirty);
     ScheduleTrigger scheduleTrigger = new ScheduleTrigger(TaskState.Ready, new Dev2DailyTrigger(new TaskServiceConvertorFactory(), new DailyTrigger()), new Dev2TaskService(new TaskServiceConvertorFactory()), new TaskServiceConvertorFactory());
     schedulerViewModel.Trigger = scheduleTrigger;
     //------------Assert Results-------------------------
     Assert.IsTrue(schedulerViewModel.SelectedTask.IsDirty);
 }
        public void SchedulerViewModel_CreateNewTask_ShouldAddTaskToListWithDefaultSettings()
        {
            //------------Setup for test--------------------------
            var schedulerViewModel = new SchedulerViewModel(new Mock<IEventAggregator>().Object, new Mock<DirectoryObjectPickerDialog>().Object, new Mock<IPopupController>().Object, new TestAsyncWorker(), new Mock<IConnectControlViewModel>().Object);
            var resources = new ObservableCollection<IScheduledResource> { new ScheduledResource("bob", SchedulerStatus.Enabled, DateTime.MaxValue, new Mock<IScheduleTrigger>().Object, "c") { NumberOfHistoryToKeep = 1 }, new ScheduledResource("dave", SchedulerStatus.Enabled, DateTime.MaxValue, new Mock<IScheduleTrigger>().Object, "c") };

            var resourceModel = new Mock<IScheduledResourceModel>();
            resourceModel.Setup(c => c.ScheduledResources).Returns(resources);
            schedulerViewModel.ScheduledResourceModel = resourceModel.Object;
            //------------Execute Test---------------------------

            Assert.AreEqual(2, schedulerViewModel.TaskList.Count);

            schedulerViewModel.NewCommand.Execute(null);
            Assert.AreEqual(3, schedulerViewModel.TaskList.Count);
            Assert.AreEqual("New Task1", schedulerViewModel.TaskList[2].Name);
            Assert.AreEqual("New Task1", schedulerViewModel.TaskList[2].OldName);
            Assert.IsTrue(schedulerViewModel.TaskList[2].IsDirty);
            Assert.AreEqual(SchedulerStatus.Enabled, schedulerViewModel.TaskList[2].Status);
            Assert.AreEqual(string.Empty, schedulerViewModel.TaskList[2].WorkflowName);
            Assert.AreEqual(schedulerViewModel.SelectedTask, schedulerViewModel.TaskList[2]);

            schedulerViewModel.NewCommand.Execute(null);
            //------------Assert Results-------------------------
            Assert.AreEqual(4, schedulerViewModel.TaskList.Count);
            Assert.AreEqual("New Task2", schedulerViewModel.TaskList[3].Name);
            Assert.AreEqual("New Task2", schedulerViewModel.TaskList[3].OldName);
            Assert.IsTrue(schedulerViewModel.TaskList[3].IsDirty);
            Assert.AreEqual(SchedulerStatus.Enabled, schedulerViewModel.TaskList[3].Status);
            Assert.AreEqual(string.Empty, schedulerViewModel.TaskList[3].WorkflowName);
            Assert.AreEqual(schedulerViewModel.SelectedTask, schedulerViewModel.TaskList[3]);
        }
 public void SchedulerViewModel_NumberOfRecordsToKeep_SetNumberOfRecordsToKeepToNoNumeric_ValueIsZero()
 {
     //------------Setup for test--------------------------
     var schedulerViewModel = new SchedulerViewModel(new Mock<IEventAggregator>().Object, new Mock<DirectoryObjectPickerDialog>().Object, new Mock<IPopupController>().Object, new TestAsyncWorker(), new Mock<IConnectControlViewModel>().Object);
     var scheduledResourceForTest = new ScheduledResourceForTest();
     schedulerViewModel.SelectedTask = scheduledResourceForTest;
     //------------Execute Test---------------------------
     schedulerViewModel.NumberOfRecordsToKeep = "asdasd";
     //------------Assert Results-------------------------
     Assert.AreEqual("0", schedulerViewModel.NumberOfRecordsToKeep);
 }
 public void WorkSurfaceContextViewModel_Constructor_SchedularWorksurfaceContext_DebugOutputViewModelNotNull()
 {
     //------------Setup for test--------------------------
     var workSurfaceKey = new WorkSurfaceKey { WorkSurfaceContext = WorkSurfaceContext.Scheduler };
     var mockWorkSurfaceViewModel = new SchedulerViewModel();
     //------------Execute Test---------------------------
     var workSurfaceContextViewModel = new WorkSurfaceContextViewModel(workSurfaceKey, mockWorkSurfaceViewModel);
     //------------Assert Results-------------------------
     Assert.IsNotNull(workSurfaceContextViewModel);
     Assert.IsNotNull(workSurfaceContextViewModel.DebugOutputViewModel);
 }
 public void SchedulerViewModel_Password_SetPassword_IsDirty()
 {
     //------------Setup for test--------------------------
     Mock<IEventAggregator> eventAggregator = new Mock<IEventAggregator>();
     eventAggregator.Setup(c => c.Publish(It.IsAny<DebugOutputMessage>())).Verifiable();
     var schedulerViewModel = new SchedulerViewModel(eventAggregator.Object, new Mock<DirectoryObjectPickerDialog>().Object, new Mock<IPopupController>().Object, new TestAsyncWorker(), new Mock<IConnectControlViewModel>().Object);
     var scheduledResourceForTest = new ScheduledResourceForTest();
     schedulerViewModel.SelectedTask = scheduledResourceForTest;
     schedulerViewModel.ShowError("Error while saving: Logon failure: unknown user name or bad password");
     Assert.AreEqual("Error while saving: Logon failure: unknown user name or bad password", schedulerViewModel.Error);
     //------------Execute Test---------------------------
     schedulerViewModel.Password = "******";
     //------------Assert Results-------------------------
     Assert.AreEqual("", schedulerViewModel.Error);
     Assert.IsTrue(schedulerViewModel.SelectedTask.IsDirty);
 }
        public void SchedulerViewModel_ShowError_WithSaveError_HasErrorsTrue()
        {
            //------------Setup for test--------------------------
            var schedulerViewModel = new SchedulerViewModel(new Mock<IEventAggregator>().Object, new Mock<DirectoryObjectPickerDialog>().Object, new Mock<IPopupController>().Object, new TestAsyncWorker(), new Mock<IConnectControlViewModel>().Object) { SelectedTask = new ScheduledResourceForTest() };

            //------------Execute Test---------------------------
            schedulerViewModel.ShowError("Error while saving: test error");
            //------------Assert Results-------------------------
            Assert.IsTrue(schedulerViewModel.HasErrors);
        }
 public void SchedulerViewModel_SelectedTask_SetValueWithHistoryTab_ShouldFirePropertyChangedNotifications()
 {
     //------------Setup for test--------------------------
     var _selectedTaskChanged = false;
     var _triggerChange = false;
     var _statusChange = false;
     var _workflowNameChange = false;
     var _nameChange = false;
     var _runasapChange = false;
     var _numRecordsChange = false;
     var _triggerTextChange = false;
     var _historyMustChange = false;
     var _accountNameChange = false;
     var _passwordChange = false;
     var _errorsChange = false;
     var _errorChange = false;
     var _selectedHistoryChange = false;
     var schedulerViewModel = new SchedulerViewModel();
     var activeItem = new TabItem { Header = "History" };
     schedulerViewModel.ActiveItem = activeItem;
     schedulerViewModel.PropertyChanged += delegate(object sender, PropertyChangedEventArgs args)
     {
         switch(args.PropertyName)
         {
             case "SelectedTask":
                 _selectedTaskChanged = true;
                 break;
             case "Trigger":
                 _triggerChange = true;
                 break;
             case "Status":
                 _statusChange = true;
                 break;
             case "WorkflowName":
                 _workflowNameChange = true;
                 break;
             case "Name":
                 _nameChange = true;
                 break;
             case "RunAsapIfScheduleMissed":
                 _runasapChange = true;
                 break;
             case "NumberOfRecordsToKeep":
                 _numRecordsChange = true;
                 break;
             case "TriggerText":
                 _triggerTextChange = true;
                 break;
             case "History":
                 _historyMustChange = true;
                 break;
             case "AccountName":
                 _accountNameChange = true;
                 break;
             case "Password":
                 _passwordChange = true;
                 break;
             case "Errors":
                 _errorsChange = true;
                 break;
             case "Error":
                 _errorChange = true;
                 break;
             case "SelectedHistory":
                 _selectedHistoryChange = true;
                 break;
         }
     };
     //------------Execute Test---------------------------
     schedulerViewModel.SelectedTask = new ScheduledResourceForTest();
     //------------Assert Results-------------------------
     Assert.IsTrue(_selectedTaskChanged);
     Assert.IsTrue(_triggerChange);
     Assert.IsTrue(_statusChange);
     Assert.IsTrue(_workflowNameChange);
     Assert.IsTrue(_nameChange);
     Assert.IsTrue(_runasapChange);
     Assert.IsTrue(_numRecordsChange);
     Assert.IsTrue(_triggerTextChange);
     Assert.IsTrue(_historyMustChange);
     Assert.IsTrue(_accountNameChange);
     Assert.IsTrue(_passwordChange);
     Assert.IsTrue(_errorsChange);
     Assert.IsTrue(_errorChange);
     Assert.IsTrue(_selectedHistoryChange);
 }
        public void SchedulerViewModel_DeleteTask_DeleteWhenEnvironmentIsntConnected_ShouldShowError()
        {
            //------------Setup for test--------------------------

            Mock<IPopupController> mockPopUpController = new Mock<IPopupController>();
            mockPopUpController.Setup(c => c.ShowDeleteConfirmation(It.IsAny<string>())).Returns(MessageBoxResult.Yes);
            var schedulerViewModel = new SchedulerViewModel(new Mock<IEventAggregator>().Object, new Mock<DirectoryObjectPickerDialog>().Object, mockPopUpController.Object, new TestAsyncWorker(), new Mock<IConnectControlViewModel>().Object);
            var env = new Mock<IEnvironmentModel>();
            var auth = new Mock<IAuthorizationService>();
            env.Setup(a => a.IsConnected).Returns(false);
            env.Setup(a => a.AuthorizationService).Returns(auth.Object);
            auth.Setup(a => a.IsAuthorized(AuthorizationContext.Administrator, null)).Returns(true).Verifiable();
            schedulerViewModel.CurrentEnvironment = env.Object;
            var resources = new ObservableCollection<IScheduledResource> { new ScheduledResource("bob", SchedulerStatus.Enabled, DateTime.MaxValue, new Mock<IScheduleTrigger>().Object, "c") { NumberOfHistoryToKeep = 1 }, new ScheduledResource("dave", SchedulerStatus.Enabled, DateTime.MaxValue, new Mock<IScheduleTrigger>().Object, "c") };

            var resourceModel = new Mock<IScheduledResourceModel>();
            resourceModel.Setup(c => c.ScheduledResources).Returns(resources);
            resourceModel.Setup(c => c.DeleteSchedule(It.IsAny<IScheduledResource>())).Verifiable();
            schedulerViewModel.ScheduledResourceModel = resourceModel.Object;
            //------------Execute Test---------------------------
            Assert.AreEqual(2, schedulerViewModel.TaskList.Count);
            schedulerViewModel.SelectedTask = schedulerViewModel.TaskList[0];

            schedulerViewModel.DeleteCommand.Execute(null);
            //------------Assert Results-------------------------
            Assert.AreEqual("Error while saving: Server unreachable.", schedulerViewModel.Error);
        }
        public void SchedulerViewModel_DeleteTask_DeleteSecondTask_ShouldDeleteTaskFromList()
        {
            //------------Setup for test--------------------------

            Mock<IPopupController> mockPopUpController = new Mock<IPopupController>();
            mockPopUpController.Setup(c => c.ShowDeleteConfirmation(It.IsAny<string>())).Returns(MessageBoxResult.Yes);
            var schedulerViewModel = new SchedulerViewModel(new Mock<IEventAggregator>().Object, new Mock<DirectoryObjectPickerDialog>().Object, mockPopUpController.Object, new TestAsyncWorker(), new Mock<IConnectControlViewModel>().Object);
            var env = new Mock<IEnvironmentModel>();
            var auth = new Mock<IAuthorizationService>();
            env.Setup(a => a.IsConnected).Returns(true);
            env.Setup(a => a.AuthorizationService).Returns(auth.Object);
            auth.Setup(a => a.IsAuthorized(AuthorizationContext.Administrator, null)).Returns(true).Verifiable();
            schedulerViewModel.CurrentEnvironment = env.Object;
            var resources = new ObservableCollection<IScheduledResource> { new ScheduledResource("bob", SchedulerStatus.Enabled, DateTime.MaxValue, new Mock<IScheduleTrigger>().Object, "c") { NumberOfHistoryToKeep = 1 }, new ScheduledResource("dave", SchedulerStatus.Enabled, DateTime.MaxValue, new Mock<IScheduleTrigger>().Object, "c") };

            var resourceModel = new Mock<IScheduledResourceModel>();
            resourceModel.Setup(c => c.ScheduledResources).Returns(resources);
            resourceModel.Setup(c => c.DeleteSchedule(It.IsAny<IScheduledResource>())).Verifiable();
            schedulerViewModel.ScheduledResourceModel = resourceModel.Object;
            //------------Execute Test---------------------------
            Assert.AreEqual(2, schedulerViewModel.TaskList.Count);
            schedulerViewModel.SelectedTask = schedulerViewModel.TaskList[1];

            var _taskListChange = false;
            var _historyChange = false;

            schedulerViewModel.PropertyChanged += delegate(object sender, PropertyChangedEventArgs args)
          {
              switch(args.PropertyName)
              {
                  case "TaskList":
                      _taskListChange = true;
                      break;
                  case "History":
                      _historyChange = true;
                      break;
              }
          };

            schedulerViewModel.DeleteCommand.Execute(null);
            //------------Assert Results-------------------------
            Assert.IsTrue(_taskListChange);
            Assert.IsTrue(_historyChange);
            Assert.AreEqual(1, schedulerViewModel.TaskList.Count);
            Assert.AreEqual(schedulerViewModel.SelectedTask, schedulerViewModel.TaskList[0]);
            Assert.AreEqual("bob", schedulerViewModel.TaskList[0].Name);
            Assert.AreEqual(SchedulerStatus.Enabled, schedulerViewModel.TaskList[0].Status);
            resourceModel.Verify(a => a.DeleteSchedule(It.IsAny<IScheduledResource>()), Times.Once());
        }
        public void SchedulerViewModel_Name_WasEmptyStringValidString_ClearsErrorMessage()
        {
            //------------Setup for test--------------------------
            var schedulerViewModel = new SchedulerViewModel(new Mock<IEventAggregator>().Object, new Mock<DirectoryObjectPickerDialog>().Object, new Mock<IPopupController>().Object, new TestAsyncWorker(), new Mock<IConnectControlViewModel>().Object);

            var scheduledResourceForTest = new ScheduledResourceForTest { Name = "Test" };
            schedulerViewModel.SelectedTask = scheduledResourceForTest;
            schedulerViewModel.Name = "";

            //------------------Assert Preconditions---------------------------
            Assert.AreNotEqual(null, schedulerViewModel.SelectedTask, "Scheduler view model selected task cannot be set.");
            Assert.AreEqual(string.Empty, schedulerViewModel.Name, "Scheduler view model name cannot be set.");
            Assert.IsTrue(schedulerViewModel.HasErrors, "Scheduler view model does not have errors when its name is empty.");
            Assert.AreEqual("The name can not be blank", schedulerViewModel.Error);

            //------------Execute Test---------------------------
            schedulerViewModel.Name = "This is a test";

            //------------Assert Results-------------------------
            Assert.IsFalse(schedulerViewModel.HasErrors);
            Assert.AreEqual(string.Empty, schedulerViewModel.Error);
            Assert.AreEqual("This is a test", schedulerViewModel.SelectedTask.Name);
            Assert.IsTrue(schedulerViewModel.SelectedTask.IsDirty);
        }