Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public DeleteFlowCommand Map(DeleteFlowRequest request)
        {
            var id = new Guid(request.RouteId);

            var version = ToVersion(request.HeaderIfMatch);

            var result = new DeleteFlowCommand(id, version);

            return(result);
        }
Esempio n. 3
0
        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();
        }
Esempio n. 4
0
        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();
        }
Esempio n. 5
0
        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);
        }