public async Task HandleShouldReturnOk()
        {
            //Arrange
            var id = Guid.NewGuid();
            Optional <string> name          = new Optional <string>("FlowUpdate");
            Optional <string> diagram       = new Optional <string>("diagram");
            Optional <string> filterContent = new Optional <string>("{\"sources\":[{\"id\":\"dcfe1db6-2484-42c2-9d9e-a77a28a5078d\",\"name\":\"BKAL33+KBT T\",\"description\":\"Plato Chemicals Test\",\"sourceBusinessUnits\":[]}],\"operations\":[{\"id\":\"d2760435-9d0b-4b69-adce-09017f2840c6\",\"name\":\"Unload into warehouse\",\"description\":\"Unloading goods into the warehouse\",\"icon\":null,\"tags\":[\"string\"]}]}");
            Optional <string> description   = new Optional <string>("description");
            Optional <string> image         = new Optional <string>("image");
            var flowFilter = JsonConvert.DeserializeObject <FlowFilter>(filterContent.Value);
            var flow       = new Flow(id, name.Value)
            {
                Version = 1
            };
            var version = 1;

            var flowWriteRepositoryMock = new Mock <IFlowWriteRepository>();

            flowWriteRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny <Flow>())).Returns(Task.CompletedTask);
            var flowWriteRepo = flowWriteRepositoryMock.Object;

            var flowReadRepositoryMock = new Mock <IFlowReadRepository>();

            flowReadRepositoryMock.Setup(x => x.GetAsync(id)).Returns(Task.FromResult(flow));
            var flowReadRepo = flowReadRepositoryMock.Object;

            var versionProviderMock = new Mock <IVersionProvider>();

            versionProviderMock.Setup(x => x.Generate()).Returns(version);
            var versionProvider = versionProviderMock.Object;

            var jsonServiceMock = new Mock <IJsonService <object> >();

            jsonServiceMock.Setup(x => x.Deserialize <FlowFilter>(filterContent.Value)).Returns(flowFilter);
            var jsonService = jsonServiceMock.Object;


            var command = new UpdateFlowCommand(id,
                                                name,
                                                description,
                                                image,
                                                diagram,
                                                filterContent,
                                                version
                                                );

            var handler = new UpdateFlowCommandHandler(flowWriteRepo,
                                                       flowReadRepo,
                                                       versionProvider,
                                                       jsonService);

            //Act
            var result = await handler.Handle(command, CancellationToken.None);

            //Assert
            result.IsFailure.Should().BeFalse();
            result.Should().BeOfType(typeof(Result));
        }
Exemple #2
0
        public CommandResult Update(Guid id, [FromBody] UpdateFlowCommand command)
        {
            command.setFlowId(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);
        }
Exemple #3
0
        public ICommandResult Handle(UpdateFlowCommand command)
        {
            ICommandResult result = new CommandResult();

            _loggingService.Log(this.GetType(), ELogType.Neutral, ELogLevel.Debug, new { command.Owner, command.OwnerType, command.Object, command.Path, command.RequestHost }, "FlowCommandHandler.Handle(Update)");

            try
            {
                Flow flow = new Flow(command.Owner, command.OwnerType, command.Object, command.Path);

                if (flow.Valid)
                {
                    if (_flowRepository.CheckExists(command.Id))
                    {
                        if (!_flowRepository.CheckExists(flow.Path))
                        {
                            if (_flowRepository.Update(command.Id, flow))
                            {
                                result = new CommandResult(200);
                            }
                        }

                        else if (_flowRepository.Valid)
                        {
                            result = new CommandResult(400, new Notification("Path", "Already in Use"));
                        }
                    }

                    else if (_flowRepository.Valid)
                    {
                        result = new CommandResult(400, new Notification("Flow", "Could not be found"));
                    }
                }

                else
                {
                    result = new NewFlowCommandResult(400, flow.Notifications);
                }
            }
            catch (Exception e)
            {
                _loggingService.Log(this.GetType(), ELogType.Neutral, ELogLevel.Error, new { command.Owner, command.OwnerType, command.Object, command.Path, command.RequestHost }, e);
            }

            return(result);
        }
Exemple #4
0
        public UpdateFlowCommand Map(UpdateFlowRequest request)
        {
            var id = new Guid(request.RouteId);

            var valuePairs = _jsonProvider.ToDictionary(request.BodyPatch);

            Optional <string> name          = valuePairs.GetOptional("name");
            Optional <string> description   = valuePairs.GetOptional("description");
            Optional <string> image         = valuePairs.GetOptional("image");
            Optional <string> diagram       = valuePairs.GetOptional("diagram");
            Optional <string> filterContent = valuePairs.GetOptional("filterContent");

            var version = ToVersion(request.HeaderIfMatch);

            var result = new UpdateFlowCommand(id, name, description, image, diagram, filterContent, version);

            return(result);
        }
        public void ShouldContainNoErrors()
        {
            // Arrange
            var id = Guid.NewGuid();
            Optional <string> name          = new Optional <string>("Name");
            Optional <string> description   = new Optional <string>("Description");
            Optional <string> image         = new Optional <string>("Image");
            Optional <string> diagram       = new Optional <string>("Diagram");
            Optional <string> filterContent = new Optional <string>("FilterContent");
            var version = 1;

            var command = new UpdateFlowCommand(id, name, description, image, diagram, filterContent, version);

            // Act
            var validationResult = _validator.Validate(command);
            var exists           = validationResult.Errors.Count > 0;

            // Assert
            exists.Should().BeFalse();
        }
        public void ShouldHaveFlowNameCannotStartOrEndWithWhiteSpaceValidationErrorWhenNameStartsOrEndsWithWhiteSpace(string symbols)
        {
            // Arrange
            var id                          = Guid.NewGuid();
            var invalidName                 = symbols;
            Optional <string> name          = new Optional <string>(invalidName);
            Optional <string> description   = new Optional <string>("Description");
            Optional <string> image         = new Optional <string>("Image");
            Optional <string> diagram       = new Optional <string>("Diagram");
            Optional <string> filterContent = new Optional <string>("FilterContent");
            var version                     = 1;

            var command = new UpdateFlowCommand(id, name, description, image, diagram, filterContent, version);

            // Act
            var validationResult = _validator.Validate(command);
            var exists           = validationResult.Errors.Any(a => a.PropertyName.Equals("Name") && a.ErrorMessage.Contains(ValidationFailures.FlowNameCannotStartOrEndWithWhiteSpace));

            // Assert
            exists.Should().BeTrue();
        }
        public void ShouldHaveFlowNotFoundCustomFailureWhenIdIsGuidEmpty()
        {
            // Arrange
            var id = Guid.Empty;
            Optional <string> name          = new Optional <string>("Name");
            Optional <string> description   = new Optional <string>("Description");
            Optional <string> image         = new Optional <string>("Image");
            Optional <string> diagram       = new Optional <string>("Diagram");
            Optional <string> filterContent = new Optional <string>("FilterContent");
            var version = 1;

            var command = new UpdateFlowCommand(id, name, description, image, diagram, filterContent, 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 void ShouldHaveFlowNameCannotBeEmptyValidationFailureWhenNameIsNull()
        {
            // Arrange
            var               id            = Guid.NewGuid();
            string            nameValue     = null;
            Optional <string> name          = new Optional <string>(nameValue);
            Optional <string> description   = new Optional <string>("Description");
            Optional <string> image         = new Optional <string>("Image");
            Optional <string> diagram       = new Optional <string>("Diagram");
            Optional <string> filterContent = new Optional <string>("FilterContent");
            var               version       = 1;

            var command = new UpdateFlowCommand(id, name, description, image, diagram, filterContent, version);

            // Act
            var validationResult = _validator.Validate(command);
            var exists           =
                validationResult.Errors.Any(
                    a => a.PropertyName.Equals("Name") && a.ErrorMessage.Contains(ValidationFailures.FlowNameCannotBeEmpty));

            // Assert
            exists.Should().BeTrue();
        }