Inheritance: Dev2.Settings.Security.SecurityViewModel
        public void SettingsViewModel_DoDeactivate_CancelNoReturnsTrue()
        {
            //------------Setup for test--------------------------
            var mockPopupController = new Mock<IPopupController>();
            mockPopupController.SetupAllProperties();
            mockPopupController.Setup(controller => controller.ShowSettingsCloseConfirmation()).Returns(MessageBoxResult.Cancel);
            var securityViewModel = new TestSecurityViewModel { IsDirty = true };
            var viewModel = CreateSettingsViewModel(mockPopupController.Object, CreateSettings().ToString(), "success", securityViewModel);

            viewModel.IsDirty = true;
            //------------Execute Test---------------------------
            var result = viewModel.DoDeactivate();
            //------------Assert Results-------------------------

            Assert.IsFalse(result);
        }
 public void SettingsViewModel_OnDeactivate_DirtyFalse_PopResultNo()
 {
     //------------Setup for test--------------------------
     var securityViewModel = new TestSecurityViewModel();
     var mockPopupController = new Mock<IPopupController>();
     mockPopupController.SetupAllProperties();
     mockPopupController.Setup(controller => controller.Show()).Returns(MessageBoxResult.No);
     var viewModel = CreateSettingsViewModel(mockPopupController.Object, CreateSettings().ToString(), "success", securityViewModel);
     //------------Execute Test---------------------------
     viewModel.SecurityViewModel.ResourcePermissions[0].WindowsGroup = "xxx";
     Assert.IsTrue(viewModel.IsDirty);
     viewModel.CallDeactivate();
     //------------Assert Results-------------------------
     VerifySavePopup(mockPopupController);
     Assert.IsTrue(viewModel.IsDirty);
 }
        public void SettingsViewModel_DoDeactivate_NoSavesChanges()
        {
            //------------Setup for test--------------------------            

            var mockPopupController = new Mock<IPopupController>();
            mockPopupController.SetupAllProperties();
            mockPopupController.Setup(controller => controller.ShowSettingsCloseConfirmation()).Returns(MessageBoxResult.No);
            var securityViewModel = new TestSecurityViewModel { IsDirty = true };
            var viewModel = CreateSettingsViewModel(mockPopupController.Object, CreateSettings().ToString(), "Success", securityViewModel);
            viewModel.IsDirty = true;
            bool propertyChanged = false;
            const string propertyName = "SecurityHeader";
            //------------Execute Test---------------------------
            viewModel.PropertyChanged += (sender, args) =>
            {
                if(args.PropertyName == propertyName)
                {
                    propertyChanged = true;
                }
            };

            var result = viewModel.DoDeactivate();
            //------------Assert Results-------------------------

            Assert.IsTrue(result);
            Assert.IsFalse(viewModel.IsDirty);
            Assert.IsTrue(propertyChanged);
            Assert.IsFalse(viewModel.SecurityViewModel.IsDirty);
        }
        public void SettingsViewModel_SaveCommand_NotConnected_HasErrorsIsTrueCorrectErrorMessage()
        {
            //------------Setup for test--------------------------
            var securityViewModel = new TestSecurityViewModel { IsDirty = true };
            var viewModel = CreateSettingsViewModel(CreateSettings().ToString(), null, securityViewModel);

            var environment = new Mock<IEnvironmentModel>();
            environment.Setup(e => e.IsConnected).Returns(false);
            Mock<IAuthorizationService> authService = new Mock<IAuthorizationService>();
            authService.Setup(c => c.IsAuthorized(It.IsAny<AuthorizationContext>(), It.IsAny<string>())).Returns(true);
            environment.Setup(c => c.AuthorizationService).Returns(authService.Object);
            viewModel.CurrentEnvironment = environment.Object;
            viewModel.IsDirty = true;

            //------------Execute Test---------------------------
            viewModel.SaveCommand.Execute(null);

            //------------Assert Results-------------------------            
            Assert.IsTrue(viewModel.IsDirty);
            Assert.IsFalse(viewModel.IsSaved);
            Assert.IsTrue(viewModel.HasErrors);
            Assert.AreEqual("Error while saving: Server unreachable.", viewModel.Errors);
        }
        public void SettingsViewModel_SaveCommand_ResultIsError_HasErrorsIsTrue()
        {
            //------------Setup for test--------------------------
            const string ErrorMessage = "A message that is not just the word Success.";

            var securityViewModel = new TestSecurityViewModel { IsDirty = true };
            var viewModel = CreateSettingsViewModel(CreateSettings().ToString(), ErrorMessage, securityViewModel);
            viewModel.IsDirty = true;


            //------------Execute Test---------------------------
            viewModel.SaveCommand.Execute(null);

            //------------Assert Results-------------------------
            Assert.IsTrue(viewModel.SecurityViewModel.IsDirty);
            Assert.IsTrue(viewModel.IsDirty);
            Assert.IsFalse(viewModel.IsSaved);
            Assert.IsTrue(viewModel.HasErrors);
            Assert.AreEqual(ErrorMessage, viewModel.Errors);
        }
        public void SettingsViewModel_SaveCommand_DuplicateResourcePermissions_HasErrorsIsTrueCorrectErrorMessage()
        {
            //------------Setup for test--------------------------
            var securityViewModel = new TestSecurityViewModel { IsDirty = true };
            var resourceId = Guid.NewGuid();
            securityViewModel.ResourcePermissions.Add(new WindowsGroupPermission
            {
                WindowsGroup = "Some Group",
                ResourceID = resourceId,
                IsServer = false
            });

            securityViewModel.ResourcePermissions.Add(new WindowsGroupPermission
            {
                WindowsGroup = "Some Group",
                ResourceID = resourceId,
                IsServer = false,
            });
            var viewModel = CreateSettingsViewModel(CreateSettings().ToString(), null, securityViewModel);

            var environment = new Mock<IEnvironmentModel>();
            environment.Setup(e => e.IsConnected).Returns(true);
            Mock<IAuthorizationService> authService = new Mock<IAuthorizationService>();
            authService.Setup(c => c.IsAuthorized(It.IsAny<AuthorizationContext>(), It.IsAny<string>())).Returns(true);
            environment.Setup(c => c.AuthorizationService).Returns(authService.Object);
            viewModel.CurrentEnvironment = environment.Object;
            viewModel.IsDirty = true;


            //------------Execute Test---------------------------
            viewModel.SaveCommand.Execute(null);

            //------------Assert Results-------------------------            
            Assert.IsTrue(viewModel.IsDirty);
            Assert.IsFalse(viewModel.IsSaved);
            Assert.IsTrue(viewModel.HasErrors);
            Assert.AreEqual(@"There are duplicate permissions for a resource, 
    i.e. one resource has permissions set twice with the same group. 
    Please clear the duplicates before saving.", viewModel.Errors);
        }
        public void SettingsViewModel_SaveCommand_ResultIsNull_HasErrorsIsTrue()
        {
            //------------Setup for test--------------------------
            var securityViewModel = new TestSecurityViewModel { IsDirty = true };
            var viewModel = CreateSettingsViewModel(CreateSettings().ToString(), null, securityViewModel);
            viewModel.IsDirty = true;


            //------------Execute Test---------------------------
            viewModel.SaveCommand.Execute(null);

            //------------Assert Results-------------------------
            Assert.IsTrue(viewModel.SecurityViewModel.IsDirty);
            Assert.IsTrue(viewModel.IsDirty);
            Assert.IsFalse(viewModel.IsSaved);
            Assert.IsTrue(viewModel.HasErrors);
            Assert.AreEqual(string.Format(GlobalConstants.NetworkCommunicationErrorTextFormat, "WriteSettings"), viewModel.Errors);
        }
        public void SettingsViewModel_SaveCommand_InvokesSaveOnSecurityViewModel_Done()
        {
            //------------Setup for test--------------------------
            var securityViewModel = new TestSecurityViewModel { IsDirty = true };
            var viewModel = CreateSettingsViewModel(CreateSettings().ToString(), "success", securityViewModel);
            viewModel.IsDirty = true;
            //------------Execute Test---------------------------
            viewModel.SaveCommand.Execute(null);

            //------------Assert Results-------------------------
            Assert.AreEqual(1, securityViewModel.SaveHitCount);
        }
        public void SecurityViewModel_PickWindowsGroupCommand_ResultIsEmptyArray_DoesNothing()
        {
            //------------Setup for test--------------------------
            var resourceID = Guid.NewGuid();
            const string ResourceName = "Cat\\Resource";
            var permission = new WindowsGroupPermission
            {
                IsServer = false,
                WindowsGroup = "Deploy Admins",
                View = false,
                Execute = false,
                Contribute = false,
                DeployTo = true,
                DeployFrom = true,
                Administrator = false,
                ResourceID = resourceID,
                ResourceName = ResourceName
            };

            var viewModel = new TestSecurityViewModel(new SecuritySettingsTO(new[] { permission }), new Mock<IResourcePickerDialog>().Object, new Mock<DirectoryObjectPickerDialog>().Object, new Mock<IWin32Window>().Object, new Mock<IEnvironmentModel>().Object) { Result = DialogResult.Cancel, SelectedObjects = new DirectoryObject[0] };
            //------------Execute Test---------------------------
            viewModel.PickWindowsGroupCommand.Execute(permission);

            //------------Assert Results-------------------------
            Assert.AreEqual("Deploy Admins", viewModel.ResourcePermissions[0].WindowsGroup);
        }
        public void SecurityViewModel_PickWindowsGroupCommand_ResultIsNotNull_PermissionWindowsGroupIsUpdated()
        {
            //------------Setup for test--------------------------
            var resourceID = Guid.NewGuid();
            const string ResourceName = "Cat\\Resource";
            var permission = new WindowsGroupPermission
            {
                IsServer = false,
                WindowsGroup = "Deploy Admins",
                View = false,
                Execute = false,
                Contribute = false,
                DeployTo = true,
                DeployFrom = true,
                Administrator = false,
                ResourceID = resourceID,
                ResourceName = ResourceName
            };

            var directoryObj = new DirectoryObject("Administrators", "WinNT://dev2/MyPC/Administrators", "Group", "", new object[1]);

            var picker = new Mock<DirectoryObjectPickerDialog>();

            var viewModel = new TestSecurityViewModel(new SecuritySettingsTO(new[] { permission }), new Mock<IResourcePickerDialog>().Object, picker.Object, new Mock<IWin32Window>().Object, new Mock<IEnvironmentModel>().Object) { Result = DialogResult.OK, SelectedObjects = new[] { directoryObj } };
            //------------Execute Test---------------------------
            viewModel.PickWindowsGroupCommand.Execute(viewModel.ResourcePermissions[0]);

            //------------Assert Results-------------------------
            Assert.AreEqual(directoryObj.Name, viewModel.ResourcePermissions[0].WindowsGroup);
        }