Beispiel #1
0
        public void AddLinkImmediately()
        {
            var            dict    = BuildTestTree();
            AddLinkCommand command = new AddLinkCommand(new NullDb(), dict["Node 1.1"], dict["Node 2.2"], true);

            Assert.AreEqual("Problem,Node 1,Node 1.1,Node 2.2,Node 1.2,Node 2,Node 2.1,Node 2.1.1,Node 2.2", StringifyTree(dict["Problem"]));
        }
Beispiel #2
0
        public void AddLinkTwice()
        {
            var            dict    = BuildTestTree();
            AddLinkCommand command = new AddLinkCommand(new NullDb(), dict["Node 1.1"], dict["Node 2.2"], true);

            command.Execute();
        }
Beispiel #3
0
        public void AddLinkUndoBeforeExecute()
        {
            var            dict    = BuildTestTree();
            AddLinkCommand command = new AddLinkCommand(new NullDb(), dict["Node 1.1"], dict["Node 2.2"]);

            command.Undo();
        }
Beispiel #4
0
        public void AddLinkCommand_InValid()
        {
            var command = new AddLinkCommand()
            {
                Name = null,
                Url  = "http://www.google.com"
            };

            var validator = new AddLinkCommandValidator();
            var valid     = validator.Validate(command);

            Assert.False(valid);
        }
Beispiel #5
0
        public void AddLinkCommand_Valid()
        {
            var command = new AddLinkCommand()
            {
                Name = "Google",
                Url  = "http://www.google.com"
            };

            var validator = new AddLinkCommandValidator();
            var valid     = validator.Validate(command);

            Assert.True(valid);
        }
Beispiel #6
0
        public void AddLinkAndUndo()
        {
            var            dict    = BuildTestTree();
            AddLinkCommand command = new AddLinkCommand(new NullDb(), dict["Node 1.1"], dict["Node 2.2"]);

            Assert.AreEqual(defaultTestTree, StringifyTree(dict["Problem"]));
            Assert.AreEqual(1, dict["Node 2.2"].CountParentNodes());
            command.Execute();
            Assert.AreEqual("Problem,Node 1,Node 1.1,Node 2.2,Node 1.2,Node 2,Node 2.1,Node 2.1.1,Node 2.2", StringifyTree(dict["Problem"]));
            Assert.AreEqual(2, dict["Node 2.2"].CountParentNodes());
            Assert.AreEqual(true, command.Executed);
            command.Undo();
            Assert.AreEqual(1, dict["Node 2.2"].CountParentNodes());
            Assert.AreEqual(defaultTestTree, StringifyTree(dict["Problem"]));
            Assert.AreEqual(false, command.Executed);
        }
Beispiel #7
0
        public void AddLinkCommand_Valid()
        {
            var addLinkCommand = new AddLinkCommand()
            {
                Name = "Google",
                Url  = "http://www.google.com"
            };
            var urlValidator  = new UrlValidator();
            var nameValidator = new NameValidator(maxLength: 100);

            nameValidator.Next(urlValidator);

            var validator = new AddLinkCommandValidator(nameValidator);

            var valid = validator.Validate(addLinkCommand);

            Assert.True(valid);
        }
Beispiel #8
0
        public void AddLinkCommand_Invalid()
        {
            var addLinkCommand = new AddLinkCommand()
            {
                Name = "Google",
                Url  = "invalid url"
            };
            var urlValidator  = new UrlValidator();
            var nameValidator = new NameValidator(100);

            nameValidator.Next(urlValidator);

            var validator = new AddLinkCommandValidator(nameValidator);

            var valid = validator.Validate(addLinkCommand);

            Assert.False(valid);
        }
Beispiel #9
0
        public void Execute_WithInvalidSourceFolder_ShouldShowInvalidPathErrorMessage()
        {
            // Arrange
            const string testPath       = @"c:/config.linker";
            const string testSourcePath = @"c:/some path that does not exist";
            const string testTargetPath = "testTargetDirectory";

            AddLinkCommand command = new AddLinkCommand(testSourcePath, testTargetPath, ConfigLink.LinkType.Default, testPath);

            testConfigHandler.Setup(m => m.LoadConfig(testPath)).Returns(testConfig.Object);

            // Act
            command.Execute(testConsole, testConfigHandler.Object, testFileSystem, testPathFormatter);

            // Assert
            Assert.IsTrue(testConsole.GetHistory().Contains("does not exist", StringComparison.OrdinalIgnoreCase));
            Assert.IsTrue(testConsole.GetHistory().Contains(testSourcePath, StringComparison.OrdinalIgnoreCase));
        }
Beispiel #10
0
        public void Execute_WithLinkFlagJunction_ShouldCreateJunctionLink()
        {
            // Arrange
            const string testPath                  = @"c:/config.linker";
            const string testSourcePath            = @"c:/demo/";
            const string testTargetPath            = @"c:/folder/anotherfolder/yetanotherfolder";
            const ConfigLink.LinkType testLinkType = ConfigLink.LinkType.Junction;

            AddLinkCommand command = new AddLinkCommand(testSourcePath, testTargetPath, testLinkType, testPath);

            testConfigHandler.Setup(m => m.LoadConfig(testPath)).Returns(testConfig.Object);

            // Act
            command.Execute(testConsole, testConfigHandler.Object, testFileSystem, testPathFormatter);

            // Assert
            Assert.IsTrue(testConfigHandler.Object.LoadConfig(testPath).LinkList.Any(link =>
                                                                                     link.sourcePath.Equals(testSourcePath) && link.targetPath.Equals(testTargetPath) && link.linkType == testLinkType));
        }
Beispiel #11
0
        public void AddLinkCommand_Valid()
        {
            var addLinkCommand = new AddLinkCommand()
            {
                Name = "Google",
                Url = "http://www.google.com"
            };

            Link link = null;

            if (!string.IsNullOrEmpty(addLinkCommand.Name) && addLinkCommand.Name.Length < 100)
            {
                if (Uri.IsWellFormedUriString(addLinkCommand.Url, UriKind.Absolute))
                {
                    link = new Link(addLinkCommand.Name, addLinkCommand.Url);
                }
            }

            Assert.NotNull(link);
        }
Beispiel #12
0
        public void Execute_WithOnlyRequiredArguments_WillCreateDefaultDirectoryLink()
        {
            // Arrange
            const string testPath       = @"c:/config.linker";
            const string testSourcePath = @"c:/demo/";
            const string testTargetPath = "testTargetDirectory";

            AddLinkCommand command = new AddLinkCommand(testSourcePath, testTargetPath, ConfigLink.LinkType.Default, testPath);

            testLinks.Add(testLinkElements[0]);
            testLinks.Add(testLinkElements[1]);
            testConfigHandler.Setup(m => m.LoadConfig(testPath)).Returns(testConfig.Object);

            // Act
            command.Execute(testConsole, testConfigHandler.Object, testFileSystem, testPathFormatter);

            // Assert
            Assert.IsTrue(testConfigHandler.Object.LoadConfig(testPath).LinkList.Any(link =>
                                                                                     link.sourcePath.Equals(testSourcePath) && link.targetPath.Equals(testTargetPath) && link.linkType == ConfigLink.LinkType.Default));
        }
Beispiel #13
0
        public void Execute_WithOnlyRequiredArgumentsRunTwice_ShouldShowDuplicatePathErrorMessage()
        {
            // Arrange
            const string testPath       = @"c:/config.linker";
            const string testSourcePath = @"c:/demo/";
            const string testTargetPath = "testTargetDirectory";

            AddLinkCommand command = new AddLinkCommand(testSourcePath, testTargetPath, ConfigLink.LinkType.Default, testPath);

            testConfigHandler.Setup(m => m.LoadConfig(testPath)).Returns(testConfig.Object);

            // Act
            testConsole.ShouldRecordHistory = false;
            command.Execute(testConsole, testConfigHandler.Object, testFileSystem, testPathFormatter);

            testConsole.ShouldRecordHistory = true;
            command.Execute(testConsole, testConfigHandler.Object, testFileSystem, testPathFormatter);

            // Assert
            Assert.IsTrue(testConsole.GetHistory().Contains("already exists", StringComparison.OrdinalIgnoreCase));
            Assert.IsTrue(testConsole.GetHistory().Contains(testTargetPath, StringComparison.OrdinalIgnoreCase));
        }
Beispiel #14
0
 private void OnToolStripButtonAddLinkClick(object sender, EventArgs e)
 {
     IUICommand command = new AddLinkCommand(this, nantProject);
     RunSynchronousCommand(command, delegate(CommandExecutionResult result)
                                        {
                                            if ((bool)result.CommandOutput)
                                            {
                                                IUICommand updateCommand = new UpdateCommand(nantProject);
                                                RunASyncCommand(updateCommand);
                                            }
                                        });
 }
Beispiel #15
0
 public bool Validate(AddLinkCommand command)
 => _validator.IsValid(command);