void DeleteTask() { if (SelectedTask != null && CurrentEnvironment != null) { if (CurrentEnvironment.IsConnected) { if (CurrentEnvironment.AuthorizationService.IsAuthorized(AuthorizationContext.Administrator, null)) { if (_popupController.ShowDeleteConfirmation(SelectedTask.Name) == MessageBoxResult.Yes) { int index = ScheduledResourceModel.ScheduledResources.IndexOf(SelectedTask); int indexInFilteredList = TaskList.IndexOf(SelectedTask); if (index != -1) { Dev2Logger.Log.Info(String.Format("Delete Schedule Name: {0} Resource:{1} Env:{2}", SelectedTask.Name, SelectedTask.ResourceId, CurrentEnvironment.Name)); ScheduledResourceModel.DeleteSchedule(SelectedTask); //if delete is successfull then do the code below ScheduledResourceModel.ScheduledResources.RemoveAt(index); NotifyOfPropertyChange(() => TaskList); if (indexInFilteredList <= TaskList.Count && indexInFilteredList > 0) { SelectedTask = TaskList[indexInFilteredList - 1]; } else if (indexInFilteredList == 0 && TaskList.Count > 0) { SelectedTask = TaskList[0]; } } NotifyOfPropertyChange(() => History); } } else { ShowError(@"Error while saving: You don't have permission to schedule on this server. You need Administrator permission."); } } else { ShowError(NotConnectedErrorMessage); } } }
public void ScheduledResourceModel_Delete_InValid() { //setup SetupSingleTask(); var model = new ScheduledResourceModel(_mockService.Object, _folderId, _agentPath, _convertorFactory.Object, @"c:\", _wrapper.Object, a => a.WorkflowName); var mockFolder = new Mock <ITaskFolder>(); var resource = new Mock <IScheduledResource>(); //expectations _mockService.Setup(a => a.GetFolder(_folderId)).Returns(_folder.Object); _folder.Setup(a => a.ValidTasks).Returns(new List <IDev2Task>()); _mockService.Setup(a => a.GetFolder("WareWolf")).Returns(mockFolder.Object); mockFolder.Setup(a => a.TaskExists("Dora")).Returns(false); mockFolder.Setup(a => a.DeleteTask("Dora", false)).Verifiable(); resource.Setup(a => a.Name).Returns("Dora"); //test model.DeleteSchedule(resource.Object); }