예제 #1
0
        public void WhenExecuteCommandWithValidTemplateConfig_CommandManager_ShouldExecuteReplaces()
        {
            var myAbsolutePath = @"c:\absolute\my\Path";
            var myPath         = @"my\Path";
            var myTemplateName = "My template name";
            var myNewPathName  = "MySecondApp";
            var myOldValue     = "myOldValue";
            var myNewVale      = "myNewValue";
            var fileService    = new FileServiceMock()
            {
                DDTemplateConfigReturn = new DDTemplateConfig()
                {
                    TemplateName       = myTemplateName,
                    IgnorePathPatterns = new List <string>(),
                    ReplacePairs       = new List <ReplacePair>()
                    {
                        new ReplacePair()
                        {
                            ApplyForDirectories  = true,
                            ApplyForFileContents = true,
                            ApplyForFileNames    = true,
                            ApplyForFilePattern  = "*.*",
                            OldValue             = myOldValue,
                            ReplaceDescription   = "My replace description"
                        }
                    }
                },
                ExistsTemplateConfigFileReturn = true,
                ExistsDirectoryReturn          = true,
                AbsoluteCurrentPathReturn      = myAbsolutePath
            };

            var consoleInputs = new List <string>()
            {
                myNewPathName,
                myNewVale
            };

            var commandDefinition = new TemplateCommand(fileService, _storedDataService);

            var instance = new CommandManager(_loggerServiceMock, _storedDataService, _cryptoServiceMock);

            instance.RegisterCommand(commandDefinition);

            var inputRequest = new InputRequest(
                commandDefinition.GetInvocationCommandName(),
                commandDefinition.CommandPathParameter.GetInvokeName(),
                myPath);

            instance.ExecuteInputRequest(inputRequest, consoleInputs);

            //Assert.Equal(fileService.CreatedDirectory, myAbsolutePath);
            Assert.Equal(fileService.ClonedDirectorySource, myPath);
            Assert.Equal(fileService.ClonedDirectoryDestination, myAbsolutePath);
            Assert.Equal(fileService.ReplacedStringInPathsNewValue, myNewVale);
            Assert.Equal(fileService.ReplacedStringInPathsOldValue, myOldValue);
            Assert.Equal(fileService.ReplacedFilesContentsPath, myAbsolutePath);
            Assert.Equal(fileService.ReplacedFilesNamesPath, myAbsolutePath);
            Assert.Equal(fileService.ReplacedSubDirectoriesPath, myAbsolutePath);
        }
예제 #2
0
        public void WhenExecuteCommandWithoutPathParameter_CommandManager_ShouldThrowException()
        {
            var fileService       = new FileServiceMock();
            var commandDefinition = new TemplateCommand(fileService, _storedDataService);

            var instance = new CommandManager(_loggerServiceMock, _storedDataService, _cryptoServiceMock);

            instance.RegisterCommand(commandDefinition);

            var inputRequest = new InputRequest(
                commandDefinition.GetInvocationCommandName());

            Assert.Throws <InvalidParamsException>(() =>
            {
                instance.ExecuteInputRequest(inputRequest);
            });
        }
예제 #3
0
        public void WhenExecuteCommandWithNonExistingTemplateConfigFile_CommandManager_ShouldThrowException()
        {
            var myPath      = @"my\Path";
            var fileService = new FileServiceMock()
            {
                ExistsTemplateConfigFileReturn = false, ExistsDirectoryReturn = true
            };
            var commandDefinition = new TemplateCommand(fileService, _storedDataService);

            var instance = new CommandManager(_loggerServiceMock, _storedDataService, _cryptoServiceMock);

            instance.RegisterCommand(commandDefinition);

            var inputRequest = new InputRequest(
                commandDefinition.GetInvocationCommandName(),
                commandDefinition.CommandPathParameter.GetInvokeName(),
                myPath);

            Assert.Throws <TemplateConfigFileNotFoundException>(() =>
            {
                instance.ExecuteInputRequest(inputRequest);
            });
        }