public void SetOperationData(LinkOperationData data)
        {
            _linkOperationData = data;
            BindToFields();

            //Set up defaults
            _linkOperationData.CopyBeforeDelete = true;
        }
Esempio n. 2
0
        public Form Start()
        {
            _operationData = new LinkOperationData();

            _view.SetOperationData(_operationData);
            _view.ValidatePath += ValidatePath;
            _view.PerformOperation += PerformOperation;
            _view.ValidOperation = ValidateOperationData;
            return _view.MainForm;
        }
        private bool TryingToLinkFileToFolder(LinkOperationData linkData)
        {
            var linkToAsFolder = _folderFactory(linkData.LinkTo);
            var createLinkAtAsFile = _fileFactory(linkData.CreateLinkAt);

            if (linkToAsFolder.FolderExists() && createLinkAtAsFile.Exists())
            {
                return true;
            }

            return false;
        }
        private Boolean IsValidFileLink(LinkOperationData linkData)
        {
            IFile createLinkAtFile = _fileFactory(linkData.CreateLinkAt);
            IFile linkToFile = _fileFactory(linkData.LinkTo);

            if (linkToFile.Exists())
            {
                return createLinkAtFile.Exists() || linkData.CopyBeforeDelete;
            }

            return true;
        }
        public void ValidOperation_File_LinkToExists_ValidOperation()
        {
            String createLinkAt = "linkAt";
            String linkTo = "linkTo";
            var fileFactory = GetFileFactoryThatReturnsExistsFor(linkTo);
            var validator = new OperationValidation(fileFactory, f => new FakeFolder(f));

            var data = new LinkOperationData() { LinkTo = createLinkAt, CreateLinkAt = linkTo, CopyBeforeDelete = true };

            String errorMessage;
            Boolean valid = validator.ValidOperation(data, out errorMessage);

            Assert.IsTrue(valid);
        }
        public void ValidOperation_AttemptsToLinkFolderToFile_NotValid()
        {
            String createLinkAt = "linkAt";
            String linkTo = "linkTo";
            var fileFactory = GetFileFactoryThatReturnsExistsFor(createLinkAt);
            var folderFactory = CommandDiscoveryTests.GetFolderFactoryThatReturnsExistsFor(linkTo);
            var validator = new OperationValidation(fileFactory, folderFactory);

            var data = new LinkOperationData() { LinkTo = linkTo, CreateLinkAt = createLinkAt, CopyBeforeDelete = true };

            String errorMessage;
            Boolean valid = validator.ValidOperation(data, out errorMessage);

            Assert.IsFalse(valid);
        }
        public Form Start()
        {
            try
            {
                Process.Start("ElevatedWorker.exe");
            }
            catch (Win32Exception E)
            {
                MessageBox.Show("Could not start elevated worker.\r\n" + E.Message, "DirLinker");
                Environment.Exit(0);
            }

            _operationData = new LinkOperationData();

            _view.SetOperationData(_operationData);
            _view.ValidatePath += ValidatePath;
            _view.PerformOperation += PerformOperation;
            _view.ValidOperation = ValidateOperationData;
            return _view.MainForm;
        }
        public Boolean ValidOperation(LinkOperationData linkData, out String errorMessage)
        {
            errorMessage = String.Empty;

            if(PathsMatch(linkData))
            {
                errorMessage = "A path can not be linked to itself";
                return false;
            }

            if(!IsValidFileLink(linkData))
            {
                errorMessage = "When creating a file link the linked to file must exist";
                return false;
            }

            if (TryingToLinkFileToFolder(linkData))
            {
                errorMessage = "A file can not be linked to a folder";
                return false;
            }

            return true;
        }
 private Boolean PathsMatch(LinkOperationData linkData)
 {
     return linkData.CreateLinkAt.Equals(linkData.LinkTo, StringComparison.CurrentCultureIgnoreCase);
 }
        public void ValidOperation_ValidData_TrueIsReturned()
        {
            var validator = new OperationValidation(f => new FakeFile(f), f => new FakeFolder(f));

            var data = new LinkOperationData() { LinkTo = "test1", CreateLinkAt = "test2" };

            String errorMessage;
            Boolean valid = validator.ValidOperation(data, out errorMessage);

            Assert.IsTrue(valid);
        }
        public void ValidOperation_LinkAndPathDoNotMatch_FalseIsReturnedAlongWithErrorMessage()
        {
            var validator = new OperationValidation(f => new FakeFile(f), f => new FakeFolder(f));

            var data = new LinkOperationData() { LinkTo = "test", CreateLinkAt = "test" };
            String errorMessage;
            Boolean valid = validator.ValidOperation(data, out errorMessage);

            Assert.IsFalse(valid);
            Assert.AreEqual("A path can not be linked to itself", errorMessage);
        }
        public void ValidOperation__CreateLinkAtExistsNoCopyBeforeDeleteLinkToDoesNotExist_FalseIsReturnedAlongWithErrorMessage()
        {
            String createLinkAt = "linkAt";
            String linkTo = "linkTo";
            var fileFactory = GetFileFactoryThatReturnsExistsFor(createLinkAt);
            var validator = new OperationValidation(fileFactory, f => new FakeFolder(f));

            var data = new LinkOperationData() { LinkTo = createLinkAt, CreateLinkAt = linkTo, CopyBeforeDelete = false };

            String errorMessage;
            Boolean valid = validator.ValidOperation(data, out errorMessage);

            Assert.IsFalse(valid);
            Assert.AreEqual("When creating a file link the linked to file must exist", errorMessage);
        }
        public void PerformOperation_ValidData_CommandsQueuedInCommandRunnerFromCommandDiscovery()
        {
            List<ICommand> commandList = new List<ICommand>();
            var commandDiscovery = MockRepository.GenerateMock<ICommandDiscovery>();
            commandDiscovery.Stub(c => c.GetCommandListTask(Arg<String>.Is.Anything, Arg<String>.Is.Anything, Arg<Boolean>.Is.Anything, Arg<Boolean>.Is.Anything))
                .Return(commandList);

            var runner = MockRepository.GenerateMock<ITransactionalCommandRunner>();
            var linker = GetLinkerService(commandDiscovery, runner);

            LinkOperationData data = new LinkOperationData { CopyBeforeDelete = true, CreateLinkAt = "", LinkTo = "", OverwriteExistingFiles = true };

            linker.SetOperationData(data);

            linker.PerformOperation();

            runner.AssertWasCalled(r => r.QueueRange(commandList));
        }
        public void PerformOperation_ValidData_CommandIsRequestedFromCommandDiscovery()
        {
            String linkTo = "Test2";
            String linkFrom = "Test1";

            var commandDiscovery = MockRepository.GenerateMock<ICommandDiscovery>();
            var linker = GetLinkerService(commandDiscovery);

            LinkOperationData data = new LinkOperationData { CopyBeforeDelete = true, CreateLinkAt = linkFrom, LinkTo = linkTo, OverwriteExistingFiles = true };

            linker.SetOperationData(data);

            linker.PerformOperation();

            commandDiscovery.AssertWasCalled(d => d.GetCommandListTask(
                                                  Arg<String>.Is.Equal(linkTo),
                                                  Arg<String>.Is.Equal(linkFrom),
                                                  Arg<Boolean>.Matches(b => data.CopyBeforeDelete),
                                                  Arg<Boolean>.Matches(b => data.OverwriteExistingFiles)));
        }
        public void PerformOperation_ValidDataAndDispatcher_StatusSetToCommandDiscoveryRunning()
        {
            var commandDiscovery = MockRepository.GenerateMock<ICommandDiscovery>();
            var runner = MockRepository.GenerateMock<ITransactionalCommandRunner>();

            var linker = GetLinkerService(commandDiscovery, runner);
            var statusData = linker.GetStatusData(Dispatcher.CurrentDispatcher);
            LinkOperationData data = new LinkOperationData { CopyBeforeDelete = true, CreateLinkAt = "", LinkTo = "", OverwriteExistingFiles = true };

            linker.SetOperationData(data);

            Boolean statusSet = false;
            statusData.PropertyChanged += (s, ea) => statusSet |= ea.PropertyName.Equals("Message") && statusData.Message.Equals("Building Task List");

            linker.PerformOperation();

            Assert.IsTrue(statusSet);
        }
 public void SetOperationData(LinkOperationData linkData)
 {
     _operationData = linkData;
 }