public void WhenExecuteCommandWithTemplateNonValidTemplateName_CommandManager_ShouldThrowException() { string templatePath = "myPath"; string templateName = "myTem NONVALID plate"; var storedDataService = new StoredDataServiceMock() { ExistsTemplateReturn = false }; var fileService = new FileServiceMock() { ExistsDirectoryReturn = true, ExistsTemplateConfigFileReturn = true }; var commandDefinition = new AddTemplateCommand(storedDataService, fileService); var instance = new CommandManager(_loggerServiceMock, storedDataService, _cryptoServiceMock); instance.RegisterCommand(commandDefinition); var inputRequest = new InputRequest( commandDefinition.GetInvocationCommandName(), commandDefinition.CommandPathParameter.GetInvokeName(), templatePath, commandDefinition.CommandNameParameter.GetInvokeName(), templateName); Assert.Throws <InvalidStringFormatException>(() => { instance.ExecuteInputRequest(inputRequest); }); }
public void WhenExecuteCommandWithoutPathParameter_CommandManager_ShouldThrowException() { string templateName = "myTemplate"; var storedDataService = new StoredDataServiceMock(); var fileService = new FileServiceMock(); var commandDefinition = new AddTemplateCommand(storedDataService, fileService); var instance = new CommandManager(_loggerServiceMock, storedDataService, _cryptoServiceMock); instance.RegisterCommand(commandDefinition); var inputRequest = new InputRequest( commandDefinition.GetInvocationCommandName(), commandDefinition.CommandNameParameter.GetInvokeName(), templateName); Assert.Throws <InvalidParamsException>(() => { instance.ExecuteInputRequest(inputRequest); }); }
public async Task <IActionResult> PostTemplate([FromBody] TemplateVersionInput templateInput) { LogBeginOfRequest(); try { if (!ModelState.IsValid) { LogEndOfRequest("Failed Bad Request", 400); return(BadRequest(ModelState)); } var command = new AddTemplateCommand(templateInput); await templateService.AddTemplateCommand.HandleAsync(command); LogEndOfRequest("Success", 200); return(Ok()); } catch (Exception) { LogEndOfRequest($"Failed user with id {templateInput.AuthorId} not found", 404); return(NotFound()); } }
public void WhenExecuteCommandWithValidParameters_CommandManager_ShouldAddTemplate() { string templatePath = "myPath"; string templateName = "myTemplate"; var storedDataService = new StoredDataServiceMock() { ExistsTemplateReturn = false }; var fileService = new FileServiceMock() { ExistsDirectoryReturn = true, ExistsTemplateConfigFileReturn = true }; var commandDefinition = new AddTemplateCommand(storedDataService, fileService); var instance = new CommandManager(_loggerServiceMock, storedDataService, _cryptoServiceMock); instance.RegisterCommand(commandDefinition); var inputRequest = new InputRequest( commandDefinition.GetInvocationCommandName(), commandDefinition.CommandPathParameter.GetInvokeName(), templatePath, commandDefinition.CommandNameParameter.GetInvokeName(), templateName); instance.ExecuteInputRequest(inputRequest); var expectedPath = templatePath; var actualPath = storedDataService.AddedTemplatePath; Assert.Equal(expectedPath, actualPath); var expectedName = templateName; var actualName = storedDataService.AddedTemplateName; Assert.Equal(expectedName, actualName); }