public void ProjectCreate_Execute_WithTemplateReturnsProviderNotInstalled()
        {
            _templateWriter.Setup(t => t.Read(It.IsAny <string>())).Returns(
                @"name: Project 2
models:
    - name: Product
jobs:
- name: Default
  tasks:
  - name: Generate
    type: Generate
    provider: AspNetCoreMvc2"
                );

            var command = new CreateCommand(_console, LoggerMock.GetLogger <CreateCommand>().Object, _consoleReader.Object, _projectService.Object, _providerService.Object, _externalServiceService.Object, _templateWriter.Object)
            {
                Name     = "Project 2",
                Client   = "Company",
                Template = "Test"
            };

            var resultMessage = command.Execute();

            Assert.Equal("Please register the required providers first by using \"provider register\" command.", resultMessage);
        }
Example #2
0
        public void ShouldFailWithUnknownCommand()
        {
            var createCommand = new CreateCommand();
            var ex            = Assert.ThrowsAny <CommandParsingException>(() => createCommand.Execute("test"));

            Assert.Contains("Unrecognized command or argument 'test'", ex.Message);
        }
        public void ProjectCreate_Execute_WithTemplateReturnsExternalServiceRequired()
        {
            _templateWriter.Setup(t => t.Read(It.IsAny <string>())).Returns(
                @"name: Project 2
models:
    - name: Product
jobs:
- name: Default
  tasks:
  - name: Generate
    type: Generate
    provider: AspNetCoreMvc
  - name: Push
    type: Generate
    provider: GitHubRepositoryProvider
    configs:
      Branch: master"
                );

            var command = new CreateCommand(_console, LoggerMock.GetLogger <CreateCommand>().Object, _consoleReader.Object, _projectService.Object, _providerService.Object, _externalServiceService.Object, _templateWriter.Object)
            {
                Name     = "Project 2",
                Client   = "Company",
                Template = "Test"
            };

            var resultMessage = command.Execute();

            Assert.Equal("Please add the required external services first by using \"service add\" command.", resultMessage);
        }
Example #4
0
        public override int Run(string[] remainingArguments)
        {
            _logger = new Logger(Verbose);

            var createCommand = new CreateCommand {
                ConnectionString = ConnectionString,
                DbName           = DbName,
                Pass             = Pass,
                ScriptDir        = ScriptDir,
                Server           = Server,
                User             = User,
                Logger           = _logger,
                Overwrite        = Overwrite
            };

            try {
                createCommand.Execute(DatabaseFilesPath);
            } catch (BatchSqlFileException ex) {
                _logger.Log(TraceLevel.Info, $"{Environment.NewLine}Create completed with the following errors:");
                foreach (var e in ex.Exceptions)
                {
                    _logger.Log(TraceLevel.Info, $"- {e.FileName.Replace("/", "\\")} (Line {e.LineNumber}):");
                    _logger.Log(TraceLevel.Error, $" {e.Message}");
                }
                return(-1);
            } catch (SqlFileException ex) {
                _logger.Log(TraceLevel.Info, $@"{Environment.NewLine}An unexpected SQL error occurred while executing scripts, and the process wasn't completed.
{ex.FileName.Replace("/", "\\")} (Line {ex.LineNumber}):");
                _logger.Log(TraceLevel.Error, ex.ToString());
                return(-1);
            } catch (Exception ex) {
                throw new ConsoleHelpAsException(ex.ToString());
            }
            return(0);
        }
        public void Test_CreateExcel_ParameterInvalid_InvalidValueException()
        {
            var excelService = A.Fake <IExcelService>();

            var command = new CreateCommand(excelService);

            command.Execute(new string[] { "C", "A", "4" });
        }
Example #6
0
        public void ShouldFailWithInvalidVersionSetVersioningScheme()
        {
            var createCommand = new CreateCommand();

            string[] args = new string[] { "--configFile", String.Concat(this.configExamplesFolder, "invalidVersionSetVersioningScheme.yml") };
            var      ex   = Assert.ThrowsAny <CommandParsingException>(() => createCommand.Execute(args));

            Assert.Contains("Versioning scheme is required if an API Version Set is provided", ex.Message);
        }
        public void ShouldThrowExceptionIFileAlreadyExists()
        {
            // Given
            File.Create (FilePath).Close ();

            // When
            var command = new CreateCommand (FilePath);
            command.Execute ();
        }
Example #8
0
        public void ShouldFailWithInvalidOpenAPISpec()
        {
            var createCommand = new CreateCommand();

            string[] args = new string[] { "--configFile", String.Concat(this.configExamplesFolder, "invalidOpenAPISpec.yml") };
            var      ex   = Assert.ThrowsAny <CommandParsingException>(() => createCommand.Execute(args));

            Assert.Contains("Open API Spec is required", ex.Message);
        }
        public void ShouldCreateFile()
        {
            // When
            var command = new CreateCommand (FilePath);
            command.Execute ();

            // Then
            Assert.IsTrue (File.Exists (FilePath));
        }
Example #10
0
        public void ShouldFailWithInvalidAPIConfiguration()
        {
            var createCommand = new CreateCommand();

            string[] args = new string[] { "--configFile", String.Concat(this.invalidConfigurationFolder, "invalidAPI.yml") };
            var      ex   = Assert.ThrowsAny <CommandParsingException>(() => createCommand.Execute(args));

            Assert.Contains("API configuration is required", ex.Message);
        }
Example #11
0
        public void ShouldFailWithUnknownOption()
        {
            var createCommand = new CreateCommand();

            string[] args = new string[] { "--configurationFile", String.Concat(this.invalidConfigurationFolder, "invalidVersionSetDisplayName.yml") };
            var      ex   = Assert.ThrowsAny <CommandParsingException>(() => createCommand.Execute(args));

            Assert.Contains("Unrecognized option '--configurationFile'", ex.Message);
        }
Example #12
0
        public void ShouldFailWithInvalidLinking()
        {
            var createCommand = new CreateCommand();

            string[] args = new string[] { "--configFile", String.Concat(this.invalidConfigurationFolder, "invalidLinking.yml") };
            var      ex   = Assert.ThrowsAny <CommandParsingException>(() => createCommand.Execute(args));

            Assert.Contains("LinkTemplatesBaseUrl is required for linked templates", ex.Message);
        }
Example #13
0
        public void ShouldFailWithInvalidAuthorizationServerDisplayName()
        {
            var createCommand = new CreateCommand();

            string[] args = new string[] { "--configFile", String.Concat(this.invalidConfigurationFolder, "invalidAuthorizationServerDisplayName.yml") };
            var      ex   = Assert.ThrowsAny <CommandParsingException>(() => createCommand.Execute(args));

            Assert.Contains("Display name is required if an Authorization Server is provided", ex.Message);
        }
Example #14
0
        public void ShouldFailWithInvalidDiagnosticLoggerId()
        {
            var createCommand = new CreateCommand();

            string[] args = new string[] { "--configFile", String.Concat(this.invalidConfigurationFolder, "invalidDiagnosticLoggerId.yml") };
            var      ex   = Assert.ThrowsAny <CommandParsingException>(() => createCommand.Execute(args));

            Assert.Contains("LoggerId is required if an API diagnostic is provided", ex.Message);
        }
        public void Test_CreateExcel_20_4_Success()
        {
            var excelService = A.Fake <IExcelService>();

            var command = new CreateCommand(excelService);

            command.Execute(new string[] { "C", "20", "4" });

            A.CallTo(() => excelService.CreateExcel(20, 4, 1)).MustHaveHappenedOnceExactly();
        }
Example #16
0
 public MainWindow()
 {
     InitializeComponent();
     MatrixController <int> .panel = ListPanel;
     commandInvoker = CommandInvoker.getInstance();
     createCommand  = new CreateCommand <int>(CreationType.Operation);
     OperationController <int> .OperationsPanel = panel2;
     ListPanel.Paint += Panel1_Paint;
     createCommand.Execute();
 }
        public void ProjectCreate_Execute_ReturnsSuccessMessage()
        {
            var command = new CreateCommand(_console, LoggerMock.GetLogger <CreateCommand>().Object, _consoleReader.Object, _projectService.Object, _providerService.Object, _externalServiceService.Object, _templateWriter.Object)
            {
                Name   = "Project 2",
                Client = "Company",
            };

            var resultMessage = command.Execute();

            Assert.StartsWith("Project created:", resultMessage);
        }
        public void ShouldRollbackFileCreation()
        {
            // Given
            var command = new CreateCommand (FilePath);
            command.Execute ();

            // When
            command.Rollback ();

            // Then
            Assert.IsFalse (File.Exists (FilePath));
        }
Example #19
0
 private void ApplyButton_OnClick(object sender, RoutedEventArgs e)
 {
     AddButton.Visibility    = Visibility.Visible;
     NameTextBox.Visibility  = Visibility.Collapsed;
     ApplyButton.Visibility  = Visibility.Collapsed;
     CancelButton.Visibility = Visibility.Collapsed;
     if (CreateCommand != null && CreateCommand.CanExecute(NameTextBox.Text))
     {
         CreateCommand.Execute(NameTextBox.Text);
         NameTextBox.Text = string.Empty;
     }
 }
Example #20
0
        public void CreateEntity_ShouldCreateEntity()
        {
            // arrange
            var ev = new D2DEvent();
            var stub = new FakeRepository(new Dictionary<Type, IEnumerable<IEntity>>());
            var createCommand = new CreateCommand<D2DEvent> {Entity = ev};

            // act
            createCommand.Execute(stub);

            //assert
            Assert.AreEqual(1, stub.AddCalls.Count());
            Assert.AreEqual(ev, stub.AddCalls.First());
        }
Example #21
0
        public ExecutionResponse DeploySnapshot(string connectionString, string scriptDir, bool overwrite, bool azureMode)
        {
            try
            {
                connectionString.Should().NotBeNullOrWhiteSpace();
                scriptDir.Should().NotBeNullOrWhiteSpace();

                if (!Directory.Exists(scriptDir))
                {
                    throw new DirectoryNotFoundException($"The script directory does not exist. Directory={scriptDir}");
                }

                var createCommand = new CreateCommand
                {
                    ConnectionString = connectionString,
                    ScriptDir = scriptDir,
                    Overwrite = overwrite,
                };

                createCommand.Execute();
                return new ExecutionResponse(true);
            }
            catch (BatchSqlFileException ex)
            {
                _logger.Info($"{Environment.NewLine}Create completed with the following errors:");
                string errors = string.Empty;
                foreach (var exception in ex.Exceptions)
                {
                    errors += $"- {exception.FileName.Replace("/", "\\")} (Line {exception.LineNumber}):";
                    errors += $" {exception.Message}";
                }
                _logger.Error(errors);
                return new ExecutionResponse(false, errors, ex);
            }
            catch (SqlFileException ex)
            {
                string errors = $@"{Environment.NewLine}An unexpected SQL error occurred while executing scripts, and the process wasn't completed.
                                   {ex.FileName.Replace("/", "\\")} (Line {ex.LineNumber}):";

                _logger.Info(errors);
                _logger.Error(ex.Message);
                return new ExecutionResponse(false, errors, ex);
            }
            catch (Exception ex)
            {
                return new ExecutionResponse(false, "", ex);
            }

        }
        public void ProjectCreate_Execute_WithTemplateReturnsSuccessMessage()
        {
            _templateWriter.Setup(t => t.Read(It.IsAny <string>())).Returns(
                @"name: Project 2
models:
    - name: Product
jobs:
- name: Default
  tasks:
  - name: Generate
    type: Generate
    provider: AspNetCoreMvc
  - name: Push
    type: Generate
    provider: GitHubRepositoryProvider
    configs:
      Branch: master
      GitHubExternalService: github-default
  - name: Deploy
    type: Deploy
    provider: AzureAppService
    configs:
      AzureAppServiceExternalService: azure-default"
                );

            _consoleReader.Setup(x => x.GetPassword(It.IsAny <string>(), null, null)).Returns("testPassword");

            var console = new TestConsole(_output, "test");
            var command = new CreateCommand(console, LoggerMock.GetLogger <CreateCommand>().Object, _consoleReader.Object, _projectService.Object, _providerService.Object, _externalServiceService.Object, _templateWriter.Object)
            {
                Name     = "Project 2",
                Client   = "Company",
                Template = "Test"
            };

            var resultMessage = command.Execute();

            Assert.StartsWith("Project created:", resultMessage);
            _projectService.Verify(s => s.CreateProject(It.Is <NewProjectDto>(p => p.Models.Count > 0)), Times.Once);
        }
Example #23
0
            public void should_log_usage_message()
            {
                createCommand.Execute(new string[] { invalidArgument });

                log.Received().ErrorMessage(Arg.Is <string>(s => s == Messages.Usage));
            }
Example #24
0
 private void CreateProperty()
 {
     FillCommand();
     CreateCommand.Execute();
 }
Example #25
0
        private static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Not enough arguments !");
                return;
            }

            Config.Model = args[0].ToLower().UppercaseFirst();
            var command = "";

            if (args.Length > 1)
            {
                command = args[1].ToLower();
            }

            if (args.Length > 2)
            {
                Config.Area = args[2].ToLower().UppercaseFirst();
            }

            Config.ModelsPath     = Environment.CurrentDirectory + "\\";
            Config.ViewModelsPath = new System.IO.DirectoryInfo(Config.ModelsPath).Parent.FullName + "\\ViewModels\\";
            Config.RepositoryPath = new System.IO.DirectoryInfo(Config.ModelsPath).Parent.Parent.FullName + "\\Repository\\";
            Config.ServicePath    = new System.IO.DirectoryInfo(Config.ModelsPath).Parent.Parent.FullName + "\\Service\\";

            if (string.IsNullOrEmpty(Config.Area))
            {
                Config.ControllerPath = new System.IO.DirectoryInfo(Config.ModelsPath).Parent.Parent.Parent.FullName + "\\Portal.Web\\Controllers\\";
                Config.ViewsPath      = new System.IO.DirectoryInfo(Config.ModelsPath).Parent.Parent.Parent.FullName + "\\Portal.Web\\Views\\" + Config.Model + "\\";
            }
            else
            {
                Config.ControllerPath = new System.IO.DirectoryInfo(Config.ModelsPath).Parent.Parent.Parent.FullName + "\\Portal.Web\\Areas\\" + Config.Area + "\\Controllers\\";
                Config.ViewsPath      = new System.IO.DirectoryInfo(Config.ModelsPath).Parent.Parent.Parent.FullName + "\\Portal.Web\\Areas\\" + Config.Area + "\\Views\\" + Config.Model + "\\";
            }

            var viewsDir = new System.IO.DirectoryInfo(Config.ViewsPath);

            if (!viewsDir.Exists)
            {
                viewsDir.Create();
            }

            Config.PropertyNames        = ClassHelper.GetPropertyNames(Config.ModelsPath + Config.Model + ".cs");
            Config.PropertyTypes        = ClassHelper.GetPropertyTypes(Config.ModelsPath + Config.Model + ".cs");
            Config.PropertyDeclarations = ClassHelper.GetPropertyDeclarations(Config.ModelsPath + Config.Model + ".cs");

            switch (command)
            {
            case "sr":
            case "service":
                var iserviceCommand = new IServiceCommand();
                var serviceCommand  = new ServiceCommand();
                iserviceCommand.Execute();
                serviceCommand.Execute();
                break;

            case "rp":
            case "repository":
                var irepositoryCommand = new IRepositoryCommand();
                var repositoryCommand  = new RepositoryCommand();
                irepositoryCommand.Execute();
                repositoryCommand.Execute();
                break;

            case "vm":
            case "viewmodel":
                var viewModelCommand = new ViewModelCommand();
                viewModelCommand.Execute();
                break;

            case "ad":
            case "addmodel":
                var addModel = new AddModelCommand();
                addModel.Execute();
                break;

            case "vi":
            case "views":
                var indexCommand   = new IndexCommand();
                var createCommand  = new CreateCommand();
                var editCommand    = new EditCommand();
                var deleteCommand  = new DeleteCommand();
                var detailsCommand = new DetailsCommand();

                indexCommand.Execute();
                createCommand.Execute();
                editCommand.Execute();
                deleteCommand.Execute();
                detailsCommand.Execute();

                break;

            case "cr":
            case "controller":
                var controllerCommand = new ControllerCommand();
                controllerCommand.Execute();
                break;

            case "go":
            default:
                var goCommand = new GoCommand();
                goCommand.Execute();


                break;
            }
        }
Example #26
0
            public void should_call_execute_on_sub_command_with_no_arguments()
            {
                createCommand.Execute(new string[] { subCommandArgument });

                subCommand.Received().Execute(Arg.Is <string[]>(args => args.Length == 0));
            }