Inheritance: IScheduledResource, INotifyPropertyChanged
        private ExecuteMessage RunOutput(bool expectCorrectInput)
        {
            var esbMethod = new DeleteScheduledResource();
            var factory = new Mock<IServerSchedulerFactory>();
            var model = new Mock<IScheduledResourceModel>();
            var ws = new Mock<IWorkspace>();
            var trigger = new ScheduleTrigger(TaskState.Disabled,
                                              new Dev2DailyTrigger(new TaskServiceConvertorFactory(), new DailyTrigger(21)),
                                              new Dev2TaskService(new TaskServiceConvertorFactory()),
                                              new TaskServiceConvertorFactory());
            var res = new ScheduledResource("a", SchedulerStatus.Enabled, DateTime.Now, trigger, "dave");
            var security = new Mock<ISecurityWrapper>();
            esbMethod.SecurityWrapper = security.Object;

            Dictionary<string, StringBuilder> inp = new Dictionary<string, StringBuilder>();
            factory.Setup(
                a =>
                a.CreateModel(GlobalConstants.SchedulerFolderId, It.IsAny<ISecurityWrapper>())).Returns(model.Object);
            Dev2JsonSerializer serialiser = new Dev2JsonSerializer();
            if(expectCorrectInput)
            {

                model.Setup(a => a.DeleteSchedule(It.IsAny<ScheduledResource>())).Verifiable();
                inp.Add("Resource", serialiser.SerializeToBuilder(res));
            }

            esbMethod.SchedulerFactory = factory.Object;

            var output = esbMethod.Execute(inp, ws.Object);
            if(expectCorrectInput)
                model.Verify(a => a.DeleteSchedule(It.IsAny<ScheduledResource>()));
            return serialiser.Deserialize<ExecuteMessage>(output);

        }
Ejemplo n.º 2
0
        private IScheduledResource CreateScheduledResource(IDev2Task arg, ITrigger trigger, DateTime nextDate, List <string> split)
        {
            var id = split[5];

            Guid.TryParse(id, out Guid resourceId);

            var res = new ScheduledResource(arg.Definition.Data,
                                            arg.Definition.Settings.Enabled ? SchedulerStatus.Enabled : SchedulerStatus.Disabled,
                                            nextDate,
                                            new ScheduleTrigger(arg.State, _factory.SanitiseTrigger(trigger),
                                                                _taskService, _factory), split[1], split[5])
            {
                Status = arg.Definition.Settings.Enabled ? SchedulerStatus.Enabled : SchedulerStatus.Disabled,
                RunAsapIfScheduleMissed = arg.Definition.Settings.StartWhenAvailable,
                UserName = arg.Definition.UserName,
            };

            string resWorkflowName;

            if (resourceId == Guid.Empty)
            {
                resWorkflowName = split[1];
            }
            else
            {
                try
                {
                    resWorkflowName = _pathResolve(res);
                }
                catch (NullReferenceException)
                {
                    resWorkflowName = split[1];
                    res.Errors.AddError($"Workflow: {resWorkflowName} not found. Task is invalid.");
                }
            }
            res.WorkflowName = resWorkflowName;

            return(res);
        }
Ejemplo n.º 3
0
 public void CreateNewTask()
 {
     if(CurrentEnvironment != null)
     {
         Dev2Logger.Log.Info(String.Format("Delete Schedule Environment: {0} ",CurrentEnvironment.Name));
     }
     var dev2DailyTrigger = new Dev2DailyTrigger(new TaskServiceConvertorFactory(), new DailyTrigger());
     var scheduleTrigger = _schedulerFactory.CreateTrigger(TaskState.Ready, dev2DailyTrigger);
     ScheduledResource scheduledResource = new ScheduledResource(NewTaskName + _newTaskCounter, SchedulerStatus.Enabled, scheduleTrigger.Trigger.Instance.StartBoundary, scheduleTrigger, string.Empty) { IsDirty = true };
     scheduledResource.OldName = scheduledResource.Name;
     ScheduledResourceModel.ScheduledResources.Add(scheduledResource);
     _newTaskCounter++;
     NotifyOfPropertyChange(() => TaskList);
     SelectedTask = ScheduledResourceModel.ScheduledResources.Last();
     WorkflowName = string.Empty;
     SelectedTask.IsNew = true;
 }
 public void SchedulerViewModel_SaveCommand_WithNewNameDiffToOldNameCancelDialogResponse_IsNewFalse_ShouldShowDialog()
 {
     //------------Setup for test--------------------------
     var resources = new ObservableCollection<IScheduledResource>();
     var scheduledResourceForTest = new ScheduledResource("Task2", SchedulerStatus.Enabled, DateTime.MaxValue, new Mock<IScheduleTrigger>().Object, "TestFlow1") { OldName = "Task1", IsDirty = true };
     scheduledResourceForTest.IsDirty = true;
     resources.Add(scheduledResourceForTest);
     resources.Add(new ScheduledResource("Task3", SchedulerStatus.Enabled, DateTime.MaxValue, new Mock<IScheduleTrigger>().Object, "TestFlow1") { OldName = "Task3", IsDirty = true });
     Mock<IPopupController> mockPopupController = new Mock<IPopupController>();
     mockPopupController.Setup(c => c.ShowNameChangedConflict(It.IsAny<string>(), It.IsAny<string>())).Returns(MessageBoxResult.Cancel).Verifiable();
     var schedulerViewModel = new SchedulerViewModelForTest(new Mock<IEventAggregator>().Object, new Mock<DirectoryObjectPickerDialog>().Object, mockPopupController.Object, new TestAsyncWorker());
     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 mockScheduledResourceModel = new Mock<IScheduledResourceModel>();
     mockScheduledResourceModel.Setup(model => model.ScheduledResources).Returns(resources);
     mockScheduledResourceModel.Setup(model => model.Save(It.IsAny<IScheduledResource>(), It.IsAny<string>(), It.IsAny<string>())).Verifiable();
     schedulerViewModel.ScheduledResourceModel = mockScheduledResourceModel.Object;
     schedulerViewModel.SelectedTask = schedulerViewModel.TaskList[0];
     schedulerViewModel.SelectedTask.IsNew = false;
     //------------Execute Test---------------------------
     schedulerViewModel.SaveCommand.Execute(null);
     //------------Assert Results-------------------------
     Assert.IsFalse(schedulerViewModel.GetCredentialsCalled);
     string errorMessage;
     mockScheduledResourceModel.Verify(model => model.Save(It.IsAny<IScheduledResource>(), out errorMessage), Times.Never());
     Assert.AreEqual("Task2", schedulerViewModel.TaskList[0].Name);
     mockPopupController.Verify(c => c.ShowNameChangedConflict(It.IsAny<string>(), It.IsAny<string>()), Times.Once());
 }
        public void SchedulerViewModel_SaveCommand_AuthorizationFails()
        {
            //------------Setup for test--------------------------
            var resources = new ObservableCollection<IScheduledResource>();
            var scheduledResourceForTest = new ScheduledResource("Task2", SchedulerStatus.Enabled, DateTime.MaxValue, new Mock<IScheduleTrigger>().Object, "TestFlow1") { OldName = "New Task 1", IsDirty = true };
            scheduledResourceForTest.IsDirty = true;
            resources.Add(scheduledResourceForTest);
            resources.Add(new ScheduledResource("Task3", SchedulerStatus.Enabled, DateTime.MaxValue, new Mock<IScheduleTrigger>().Object, "TestFlow1") { OldName = "Task3", IsDirty = true });
            Mock<IPopupController> mockPopupController = new Mock<IPopupController>();
            mockPopupController.Setup(c => c.ShowNameChangedConflict(It.IsAny<string>(), It.IsAny<string>())).Returns(MessageBoxResult.Yes).Verifiable();
            var schedulerViewModel = new SchedulerViewModelForTest(new Mock<IEventAggregator>().Object, new Mock<DirectoryObjectPickerDialog>().Object, mockPopupController.Object, new TestAsyncWorker());
            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(false).Verifiable();
            schedulerViewModel.CurrentEnvironment = env.Object;
            var mockScheduledResourceModel = new Mock<IScheduledResourceModel>();
            mockScheduledResourceModel.Setup(model => model.ScheduledResources).Returns(resources);

            schedulerViewModel.ScheduledResourceModel = mockScheduledResourceModel.Object;
            schedulerViewModel.SelectedTask = schedulerViewModel.TaskList[0];
            //------------Execute Test---------------------------
            schedulerViewModel.SaveCommand.Execute(null);
            //------------Assert Results-------------------------
            auth.Verify(a => a.IsAuthorized(AuthorizationContext.Administrator, null));
            Assert.AreEqual(schedulerViewModel.Errors.FetchErrors().Count, 1);
            Assert.AreEqual(@"Error while saving: You don't have permission to schedule on this server.
You need Administrator permission.", schedulerViewModel.Errors.FetchErrors().FirstOrDefault());
        }
        public void SchedulerViewModel_SaveCommand_WithNewNameDiffToOldNameYesDialogResponse_OldNameChanges()
        {
            //------------Setup for test--------------------------
            var resources = new ObservableCollection<IScheduledResource>();
            var scheduledResourceForTest = new ScheduledResource("Task2", SchedulerStatus.Enabled, DateTime.MaxValue, new Mock<IScheduleTrigger>().Object, "TestFlow1") { OldName = "Task1", IsDirty = true };
            scheduledResourceForTest.IsDirty = true;
            resources.Add(scheduledResourceForTest);
            resources.Add(new ScheduledResource("Task3", SchedulerStatus.Enabled, DateTime.MaxValue, new Mock<IScheduleTrigger>().Object, "TestFlow1") { OldName = "Task3", IsDirty = true });
            Mock<IPopupController> mockPopupController = new Mock<IPopupController>();
            mockPopupController.Setup(c => c.ShowNameChangedConflict(It.IsAny<string>(), It.IsAny<string>())).Returns(MessageBoxResult.Yes).Verifiable();
            var schedulerViewModel = new SchedulerViewModelForTest(new Mock<IEventAggregator>().Object, new Mock<DirectoryObjectPickerDialog>().Object, mockPopupController.Object, new TestAsyncWorker());
            var env = new Mock<IEnvironmentModel>();
            var auth = new Mock<IAuthorizationService>();
            env.Setup(a => a.AuthorizationService).Returns(auth.Object);
            env.Setup(a => a.IsConnected).Returns(true);
            auth.Setup(a => a.IsAuthorized(AuthorizationContext.Administrator, null)).Returns(true).Verifiable();
            schedulerViewModel.CurrentEnvironment = env.Object;
            var mockScheduledResourceModel = new Mock<IScheduledResourceModel>();
            mockScheduledResourceModel.Setup(model => model.ScheduledResources).Returns(resources);
            string test;
            mockScheduledResourceModel.Setup(model => model.Save(It.IsAny<IScheduledResource>(), out test)).Returns(true).Verifiable();
            schedulerViewModel.ScheduledResourceModel = mockScheduledResourceModel.Object;
            schedulerViewModel.SelectedTask = schedulerViewModel.TaskList[0];
            schedulerViewModel.ShowError("Error while saving: test error");
            Assert.IsTrue(schedulerViewModel.HasErrors);

            var _errorsChanged = false;
            var _errorChanged = false;
            var _taskListChanged = false;


            schedulerViewModel.PropertyChanged += delegate(object sender, PropertyChangedEventArgs args)
            {
                switch(args.PropertyName)
                {
                    case "Errors":
                        _errorsChanged = true;
                        break;
                    case "Error":
                        _errorChanged = true;
                        break;
                    case "TaskList":
                        _taskListChanged = true;
                        break;
                }
            };

            //------------Execute Test---------------------------
            schedulerViewModel.SaveCommand.Execute(null);
            //------------Assert Results-------------------------
            Assert.IsTrue(_errorsChanged);
            Assert.IsTrue(_errorChanged);
            Assert.IsTrue(_taskListChanged);
            Assert.IsFalse(schedulerViewModel.HasErrors);
            Assert.IsTrue(schedulerViewModel.GetCredentialsCalled);
            string errorMessage;
            mockScheduledResourceModel.Verify(model => model.Save(It.IsAny<IScheduledResource>(), out errorMessage), Times.Once());
            Assert.AreEqual("Task2", schedulerViewModel.TaskList[0].Name);
            Assert.AreEqual("Task2", schedulerViewModel.TaskList[0].OldName);
            mockPopupController.Verify(c => c.ShowNameChangedConflict(It.IsAny<string>(), It.IsAny<string>()), Times.Once());
        }
        private List<IResourceHistory> RunOutput(bool expectCorrectInput)
        {
            var esbMethod = new GetScheduledResourceHistory();
            var security = new Mock<ISecurityWrapper>();
            esbMethod.SecurityWrapper = security.Object;
            var factory = new Mock<IServerSchedulerFactory>();
            var model = new Mock<IScheduledResourceModel>();
            var ws = new Mock<IWorkspace>();
            var history = new List<IResourceHistory>
                {
                    new ResourceHistory("", new List<IDebugState> {new DebugState()},
                                        new EventInfo(DateTime.MinValue, TimeSpan.MaxValue, DateTime.MaxValue, ScheduleRunStatus.Error, "115"),
                                        "leon")
                };
            var trigger = new ScheduleTrigger(TaskState.Disabled,
                                              new Dev2DailyTrigger(new TaskServiceConvertorFactory(), new DailyTrigger(21)),
                                              new Dev2TaskService(new TaskServiceConvertorFactory()),
                                              new TaskServiceConvertorFactory());
            var res = new ScheduledResource("a", SchedulerStatus.Enabled, DateTime.Now, trigger, "dave");
            Dictionary<string, StringBuilder> inp = new Dictionary<string, StringBuilder>();
            factory.Setup(
                a =>
                a.CreateModel(GlobalConstants.SchedulerFolderId, It.IsAny<ISecurityWrapper>())).Returns(model.Object);
            Dev2JsonSerializer serialiser = new Dev2JsonSerializer();
            if(expectCorrectInput)
            {

                model.Setup(a => a.CreateHistory(It.IsAny<ScheduledResource>())).Returns(history).Verifiable();
                inp.Add("Resource", serialiser.SerializeToBuilder(res));
            }

            esbMethod.SchedulerFactory = factory.Object;

            var output = esbMethod.Execute(inp, ws.Object);

            return serialiser.Deserialize<List<IResourceHistory>>(output);

        }
Ejemplo n.º 8
0
        private IScheduledResource CreateScheduledResource(IDev2Task arg)
        {
            ITrigger      trigger;
            DateTime      nextDate;
            List <string> output;

            using (var action = ConvertorFactory.CreateExecAction(arg.Action))
            {
                trigger  = arg.Trigger;
                nextDate = trigger.StartBoundary;
                output   = action.Arguments.Split(ArgWrapper).Where(a => !String.IsNullOrEmpty(a.Trim())).ToList();
            }
            if (output.Count == ArgCount && output.All(a => a.Contains(NameSeperator)))
            {
                var split = output.SelectMany(a => a.Split(NameSeperator)).ToList();
                try
                {
                    var  id = split[5];
                    Guid resourceId;
                    Guid.TryParse(id, out resourceId);

                    var res = new ScheduledResource(arg.Definition.Data,
                                                    arg.Definition.Settings.Enabled ? SchedulerStatus.Enabled : SchedulerStatus.Disabled,
                                                    nextDate,
                                                    new ScheduleTrigger(arg.State, _factory.SanitiseTrigger(trigger),
                                                                        _taskService, _factory), split[1], split[5])
                    {
                        Status = arg.Definition.Settings.Enabled ? SchedulerStatus.Enabled : SchedulerStatus.Disabled,
                        RunAsapIfScheduleMissed = arg.Definition.Settings.StartWhenAvailable,
                        UserName = arg.Definition.UserName,
                    };

                    string resWorkflowName;
                    if (resourceId == Guid.Empty)
                    {
                        resWorkflowName = split[1];
                    }
                    else
                    {
                        try
                        {
                            resWorkflowName = _pathResolve(res);
                        }
                        catch (NullReferenceException)
                        {
                            resWorkflowName = split[1];
                            res.Errors.AddError($"Workflow: {resWorkflowName} not found. Task is invalid.");
                        }
                    }
                    res.WorkflowName = resWorkflowName;

                    return(res);
                }
                finally
                {
                    arg.Dispose();
                }
            }
            if (output.Count == ArgCountOld && output.All(a => a.Contains(NameSeperator)))
            {
                var split = output.SelectMany(a => a.Split(NameSeperator)).ToList();
                try
                {
                    return(new ScheduledResource(arg.Definition.Data,
                                                 arg.Definition.Settings.Enabled ? SchedulerStatus.Enabled : SchedulerStatus.Disabled,
                                                 nextDate,
                                                 new ScheduleTrigger(arg.State, _factory.SanitiseTrigger(trigger),
                                                                     _taskService, _factory), split[1], Guid.Empty.ToString())
                    {
                        Status = arg.Definition.Settings.Enabled ? SchedulerStatus.Enabled : SchedulerStatus.Disabled,
                        RunAsapIfScheduleMissed = arg.Definition.Settings.StartWhenAvailable,
                        UserName = arg.Definition.UserName
                    });
                }
                finally
                {
                    arg.Dispose();
                }
            }

            throw new InvalidScheduleException($"Invalid resource found:{arg.Definition.Data}"); // this should not be reachable because isvaliddev2task checks same conditions
        }
        private StringBuilder RunOutput()
        {
            var esbMethod = new GetScheduledResources();
            _factory = new Mock<IServerSchedulerFactory>();
            var security = new Mock<ISecurityWrapper>();
            esbMethod.SecurityWrapper = security.Object;
            var model = new Mock<IScheduledResourceModel>();
            var ws = new Mock<IWorkspace>();
            var trigger = new ScheduleTrigger(TaskState.Disabled,
                                              new Dev2DailyTrigger(new TaskServiceConvertorFactory(), new DailyTrigger(21)),
                                              new Dev2TaskService(new TaskServiceConvertorFactory()),
                                              new TaskServiceConvertorFactory());
            var res = new ScheduledResource("a", SchedulerStatus.Enabled, DateTime.Now, trigger, "dave");
            _factory.Setup(
                a =>
                a.CreateModel(GlobalConstants.SchedulerFolderId, It.IsAny<ISecurityWrapper>())).Returns(model.Object);
            model.Setup(a => a.GetScheduledResources()).Returns(new ObservableCollection<IScheduledResource>() { res });

            esbMethod.SchedulerFactory = _factory.Object;
            var output = esbMethod.Execute(new Dictionary<string, StringBuilder>(), ws.Object);
            return output;
        }