Inheritance: IScheduledResource
Esempio n. 1
0
        public void ClientScheduledResourceModel_CreateHistory_ReturnsListOfIResourceHistory()
        {
            //------------Setup for test--------------------------
            var scheduledResourceForTest = new ScheduledResourceForTest();
            var resourceHistory          = new ResourceHistoryForTest();
            var listOfHistoryResources   = new List <IResourceHistory> {
                resourceHistory
            };
            Dev2JsonSerializer serializer = new Dev2JsonSerializer();
            var serializeObject           = serializer.SerializeToBuilder(listOfHistoryResources);
            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>(), It.IsAny <Guid>())).Returns(serializeObject);
            mockConnection.Setup(connection => connection.WorkspaceID).Returns(Guid.NewGuid());
            mockEnvironmentModel.Setup(model => model.Connection).Returns(mockConnection.Object);
            var clientScheduledResourceModel = new ClientScheduledResourceModel(mockEnvironmentModel.Object);
            //------------Execute Test---------------------------
            var resourceHistories = clientScheduledResourceModel.CreateHistory(scheduledResourceForTest);

            //------------Assert Results-------------------------
            mockConnection.Verify(connection => connection.ExecuteCommand(It.IsAny <StringBuilder>(), It.IsAny <Guid>(), It.IsAny <Guid>()), Times.Once());
            Assert.AreEqual(1, resourceHistories.Count);
        }
Esempio n. 2
0
        public void ClientScheduledResourceModel_SaveScheduledResource_CallsCommunicationsController()
        {
            //------------Setup for test--------------------------
            var scheduledResourceForTest  = new ScheduledResourceForTest();
            Dev2JsonSerializer serializer = new Dev2JsonSerializer();
            var serializeObject           = serializer.SerializeToBuilder(scheduledResourceForTest);
            var esbPayLoad = new EsbExecuteRequest {
                ServiceName = "AddScheduledResourceService"
            };

            esbPayLoad.AddArgument("Resource", serializeObject);
            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>(), It.IsAny <Guid>())).Verifiable();
            mockConnection.Setup(connection => connection.WorkspaceID).Returns(Guid.NewGuid());
            mockEnvironmentModel.Setup(model => model.Connection).Returns(mockConnection.Object);
            var clientScheduledResourceModel = new ClientScheduledResourceModel(mockEnvironmentModel.Object);
            //------------Execute Test---------------------------
            string errorMessage;
            var    saved = clientScheduledResourceModel.Save(scheduledResourceForTest, out errorMessage);

            //------------Assert Results-------------------------
            mockConnection.Verify(connection => connection.ExecuteCommand(It.IsAny <StringBuilder>(), It.IsAny <Guid>(), It.IsAny <Guid>()), Times.Once());
            Assert.IsTrue(saved);
        }
 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);
 }
 public void ClientScheduledResourceModel_DeleteScheduledResource_CallsCommunicationsController()
 {
     //------------Setup for test--------------------------
     var scheduledResourceForTest = new ScheduledResourceForTest();
     Dev2JsonSerializer serializer = new Dev2JsonSerializer();
     var serializeObject = serializer.SerializeToBuilder(scheduledResourceForTest);
     var esbPayLoad = new EsbExecuteRequest { ServiceName = "DeleteScheduledResourceService" };
     esbPayLoad.AddArgument("Resource", serializeObject);
     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>(), It.IsAny<Guid>())).Verifiable();
     mockConnection.Setup(connection => connection.WorkspaceID).Returns(Guid.NewGuid());
     mockEnvironmentModel.Setup(model => model.Connection).Returns(mockConnection.Object);
     var clientScheduledResourceModel = new ClientScheduledResourceModel(mockEnvironmentModel.Object);
     //------------Execute Test---------------------------
     clientScheduledResourceModel.DeleteSchedule(scheduledResourceForTest);
     //------------Assert Results-------------------------
     mockConnection.Verify(connection => connection.ExecuteCommand(It.IsAny<StringBuilder>(), It.IsAny<Guid>(), It.IsAny<Guid>()), Times.Once());
 }
 public void ClientScheduledResourceModel_GetScheduledResources_ReturnsCollectionOfIScheduledResource()
 {
     //------------Setup for test--------------------------
     var resources = new ObservableCollection<IScheduledResource>();
     var scheduledResourceForTest = new ScheduledResourceForTest();
     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>(), It.IsAny<Guid>())).Returns(serializeObject);
     mockConnection.Setup(connection => connection.WorkspaceID).Returns(Guid.NewGuid());
     mockEnvironmentModel.Setup(model => model.Connection).Returns(mockConnection.Object);
     var clientScheduledResourceModel = new ClientScheduledResourceModel(mockEnvironmentModel.Object);
     //------------Execute Test---------------------------
     var scheduledResources = clientScheduledResourceModel.GetScheduledResources();
     //------------Assert Results-------------------------
     Assert.AreEqual(1, scheduledResources.Count);
 }
 public void ClientScheduledResourceModel_CreateHistory_ReturnsListOfIResourceHistory()
 {
     //------------Setup for test--------------------------
     var scheduledResourceForTest = new ScheduledResourceForTest();
     var resourceHistory = new ResourceHistoryForTest();
     var listOfHistoryResources = new List<IResourceHistory> { resourceHistory };
     Dev2JsonSerializer serializer = new Dev2JsonSerializer();
     var serializeObject = serializer.SerializeToBuilder(listOfHistoryResources);
     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);
     var clientScheduledResourceModel = new ClientScheduledResourceModel(mockEnvironmentModel.Object);
     //------------Execute Test---------------------------
     var resourceHistories = clientScheduledResourceModel.CreateHistory(scheduledResourceForTest);
     //------------Assert Results-------------------------
     mockConnection.Verify(connection => connection.ExecuteCommand(It.IsAny<StringBuilder>(), It.IsAny<Guid>()), Times.Once());
     Assert.AreEqual(1, resourceHistories.Count);
 }
Esempio n. 7
0
        public void ClientScheduledResourceModel_GetScheduledResources_ReturnsCollectionOfIScheduledResource()
        {
            //------------Setup for test--------------------------
            var resources = new ObservableCollection <IScheduledResource>();
            var scheduledResourceForTest = new ScheduledResourceForTest();

            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>(), It.IsAny <Guid>())).Returns(serializeObject);
            mockConnection.Setup(connection => connection.WorkspaceID).Returns(Guid.NewGuid());
            mockEnvironmentModel.Setup(model => model.Connection).Returns(mockConnection.Object);
            var clientScheduledResourceModel = new ClientScheduledResourceModel(mockEnvironmentModel.Object);
            //------------Execute Test---------------------------
            var scheduledResources = clientScheduledResourceModel.GetScheduledResources();

            //------------Assert Results-------------------------
            Assert.AreEqual(1, scheduledResources.Count);
        }
 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 ClientScheduledResourceModel_SaveScheduledResource_HasError_CallsCommunicationsController()
 {
     //------------Setup for test--------------------------
     var scheduledResourceForTest = new ScheduledResourceForTest();
     Dev2JsonSerializer serializer = new Dev2JsonSerializer();
     var serializeObject = serializer.SerializeToBuilder(scheduledResourceForTest);
     var esbPayLoad = new EsbExecuteRequest { ServiceName = "AddScheduledResourceService" };
     esbPayLoad.AddArgument("Resource", serializeObject);
     var returnMessage = new ExecuteMessage { HasError = true, Message = new StringBuilder("Error occurred") };
     var serializedReturnMessage = serializer.SerializeToBuilder(returnMessage);
     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>())).Verifiable();
     mockConnection.Setup(connection => connection.ExecuteCommand(It.IsAny<StringBuilder>(), It.IsAny<Guid>())).Returns(serializedReturnMessage);
     mockConnection.Setup(connection => connection.WorkspaceID).Returns(Guid.NewGuid());
     mockEnvironmentModel.Setup(model => model.Connection).Returns(mockConnection.Object);
     var clientScheduledResourceModel = new ClientScheduledResourceModel(mockEnvironmentModel.Object);
     //------------Execute Test---------------------------
     string errorMessage;
     var saved = clientScheduledResourceModel.Save(scheduledResourceForTest, out errorMessage);
     //------------Assert Results-------------------------
     mockConnection.Verify(connection => connection.ExecuteCommand(It.IsAny<StringBuilder>(), It.IsAny<Guid>()), Times.Once());
     Assert.IsFalse(saved);
     Assert.AreEqual("Error occurred", errorMessage);
 }
        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);
        }
        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_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_SaveCommand_UserNamePasswordSet_CallsIsAuthorised()
 {
     //------------Setup for test--------------------------
     var resources = new ObservableCollection<IScheduledResource>();
     var scheduledResourceForTest = new ScheduledResourceForTest { IsDirty = true };
     resources.Add(scheduledResourceForTest);
     scheduledResourceForTest.UserName = "******";
     scheduledResourceForTest.Password = "******";
     var schedulerViewModel = new SchedulerViewModelForTest();
     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];
     //------------Execute Test---------------------------
     schedulerViewModel.SaveCommand.Execute(null);
     //------------Assert Results-------------------------
     Assert.IsTrue(schedulerViewModel.ShowSaveErrorDialogCalled);
     Assert.IsFalse(schedulerViewModel.GetCredentialsCalled);
     string errorMessage;
     mockScheduledResourceModel.Verify(model => model.Save(It.IsAny<IScheduledResource>(), out errorMessage), Times.Once());
 }
 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 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_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_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_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_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_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);
        }