public ICommandResult Handle(DeleteFlowCommand command) { ICommandResult result = new CommandResult(); _loggingService.Log(this.GetType(), ELogType.Neutral, ELogLevel.Debug, new { command.Flow, command.RequestHost }, "FlowCommandHandler.Handle(Delete)"); try { if (_flowRepository.CheckExists(command.Flow)) { if (_flowRepository.Delete(command.Flow)) { result = new CommandResult(200); } } else if (_flowRepository.Valid) { result = new CommandResult(400, new Notification("Flow", "Could not be found")); } } catch (Exception e) { _loggingService.Log(this.GetType(), ELogType.Neutral, ELogLevel.Error, new { command.Flow, command.RequestHost }, e); } return(result); }
public DeleteFlowCommand Map(DeleteFlowRequest request) { var id = new Guid(request.RouteId); var version = ToVersion(request.HeaderIfMatch); var result = new DeleteFlowCommand(id, version); return(result); }
public void ShouldContainNoErrors() { // Arrange var id = Guid.NewGuid(); var version = 1; var command = new DeleteFlowCommand(id, version); //Act var validationResult = _validator.Validate(command); var exists = validationResult.Errors.Count > 0; // Assert exists.Should().BeFalse(); }
public void ShouldHaveFlowNotFoundCustomFailureWhenIdIsGuidEmpty() { // Arrange var id = Guid.Empty; var version = 1; var command = new DeleteFlowCommand(id, version); //Act var validationResult = _validator.Validate(command); var exists = validationResult.Errors.Any( a => a.PropertyName.Equals("Id") && a.ErrorMessage.Contains(CustomFailures.FlowNotFound)); // Assert exists.Should().BeTrue(); }
public CommandResult Delete(Guid id) { DeleteFlowCommand command = new DeleteFlowCommand() { Flow = id }; command.setRequestHost(HttpContext.Request.Host.ToString()); _loggingService.Log(this.GetType(), ELogType.Input, ELogLevel.Info, new { Flow = this.User.Identity.Name, Path = this.Request.Path, Method = this.Request.Method }); CommandResult result = (CommandResult)_flowHandler.Handle(command); _loggingService.Log(this.GetType(), ELogType.Output, ELogLevel.Info, new { Flow = this.User.Identity.Name, Path = this.Request.Path, Method = this.Request.Method, Code = this.Response.StatusCode }); HttpContext.Response.StatusCode = result.Code; return(result); }