public async Task GenerateSchemaAsync(DirectoryInfo directoryInfo, JsonHelper jsonHelper)
        {
            await jsonHelper.WriteJsonSchemaAsync <UpdateWorkflowDto>(directoryInfo, "workflow.json");

            var sample = new UpdateWorkflowDto
            {
                Name  = "my-workflow",
                Steps = new Dictionary <string, WorkflowStepDto>
                {
                    ["Draft"] = new WorkflowStepDto
                    {
                        Color       = "#ff0000",
                        Transitions = new Dictionary <string, WorkflowTransitionDto>
                        {
                            ["Published"] = new WorkflowTransitionDto()
                        }
                    },
                    ["Published"] = new WorkflowStepDto
                    {
                        Color       = "#00ff00",
                        Transitions = new Dictionary <string, WorkflowTransitionDto>
                        {
                            ["Draft"] = new WorkflowTransitionDto()
                        },
                        NoUpdate = true,
                    }
                },
                Initial = "Draft"
            };

            await jsonHelper.WriteWithSchema(directoryInfo, "workflows/__workflow.json", sample, "../__json/workflow");
        }
        public async Task GenerateSchemaAsync(ISyncService sync)
        {
            await sync.WriteJsonSchemaAsync <UpdateWorkflowDto>(new FilePath("workflow.json"));

            var sample = new UpdateWorkflowDto
            {
                Name  = "my-workflow",
                Steps = new Dictionary <string, WorkflowStepDto>
                {
                    ["Draft"] = new WorkflowStepDto
                    {
                        Color       = "#ff0000",
                        Transitions = new Dictionary <string, WorkflowTransitionDto>
                        {
                            ["Published"] = new WorkflowTransitionDto()
                        }
                    },
                    ["Published"] = new WorkflowStepDto
                    {
                        Color       = "#00ff00",
                        Transitions = new Dictionary <string, WorkflowTransitionDto>
                        {
                            ["Draft"] = new WorkflowTransitionDto()
                        },
                        NoUpdate = true
                    }
                },
                Initial = "Draft"
            };

            await sync.WriteWithSchema(new FilePath("workflows", "__workflow.json"), sample, Ref);
        }
        public void Validate_DescriptionLimitReached_BadRequest()
        {
            // arrange
            Exception exception = null;
            var       model     = new UpdateWorkflowDto
            {
                Name        = "aasdff",
                Description =
                    "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc, quis gravida magna mi a libero. Fusce vulputate eleifend sapien. Vestibulum purus quam, scelerisque ut, mollis sed, nonummy id, metus. Nullam accumsan lorem in dui. Cras ultricies mi eu turpis hendrerit fringilla. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In ac dui quis mi consectetuer lacinia. Nam pretium turpis et arcu. Duis arcu tortor, suscipit eget, imperdiet nec, imperdiet iaculis, ipsum. Sed aliquam ultrices mauris. Integer ante arcu, accumsan a, consectetuer eget, posuere ut, mauris. Praesent adipiscing. Phasellus ullamcorper ipsum rutrum nunc. Nunc nonummy metus. Vestibulum volutpat pretium libero. Cras id dui. Aenean ut eros et nisl sagittis vestibulum. Nullam nulla eros, ultricies sit amet, nonummy id, imperdiet feugiat, pede. Sed lectus. Donec mollis hendrerit risus. Phasellus nec sem in justo pellentesque facilisis. Etiam imperdiet imperdiet orci. Nunc nec neque. Phasellus leo dolor, tempus non, auctor et, hendrerit quis, nisi. Curabitur ligula sapien, tincidunt non, euismod vitae, posuere imperdiet, leo. Maecenas malesuada. Praesent congue erat at massa. Sed cursus turpis vitae tortor. Donec posuere vulputate arcu. Phasellus accumsan cursus velit. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed aliquam, nisi quis porttitor congue, elit erat euismod orci, ac placerat dolor lectus quis orci. Phasellus consectetuer vestibulum elit. Aenean tellus metus, bibendum sed, posuere ac, mattis non, nunc. Vestibulum fringilla pede sit amet augue. In turpis. Pellentesque posuere. Praesent turpis. Aenean posuere, tortor sed cursus feugiat, nunc augue blandit nunc, eu sollicitudin urna dolor sagittis lacus. Donec elit libero, sodales nec, volutpat a, suscipit non, turpis. Nullam sagittis. Suspendisse pulvinar, augue ac venenatis condimentum, sem libero volutpat nibh, nec pellentesque velit pede quis nunc. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Fusce id purus. Ut varius tincidunt libero. Phasellus dolor. Maecenas vestibulum mollis diam. Pellentesque ut neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. In dui magna, posuere eget, vestibulum et, tempor auctor, justo. In ac felis quis tortor malesuada pretium. Pellentesque auctor neque nec urna. Proin sapien ipsum, porta a, auctor quis, euismod ut, mi. Aenean viverra rhoncus pede. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Ut non enim eleifend felis pretium feugiat. Vivamus quis mi. Phasellus a est. Phase"
            };

            // act
            try
            {
                model.Validate();
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            // assert
            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(exception, typeof(BadRequestException));
            Assert.AreEqual(ErrorMessages.WorkflowDescriptionLimit, exception.Message);
        }
        public async Task UpdateWorkflowAsync_StatusChanges_SuccessfullySendsMessage()
        {
            // Arrange
            var transactionMock = new Mock <IDbTransaction>();
            var updateSatus     = new UpdateWorkflowDto()
            {
                VersionId = 1, Status = true
            };

            _workflowRepositoryMock
            .Setup(repo => repo.GetWorkflowDetailsAsync(It.IsAny <int>())).ReturnsAsync((SqlWorkflow) new SqlWorkflow()
            {
                Active = false
            });
            _workflowRepositoryMock.Setup(
                repo =>
                repo.CreateRevisionInTransactionAsync(It.IsAny <IDbTransaction>(), It.IsAny <int>(),
                                                      It.IsAny <string>())).ReturnsAsync(1);
            _workflowRepositoryMock.Setup(repo => repo.RunInTransactionAsync(It.IsAny <Func <IDbTransaction, long, Task> >()))
            .Returns(Task.Run(() => { }))
            .Callback((Func <IDbTransaction, long, Task> action) =>
            {
                action(transactionMock.Object, 0);
            });

            // Act
            await _service.UpdateWorkflowAsync(updateSatus, WorkflowId, SessionUserId);

            // Assert
            _sendMessageExecutorMock.Verify(a => a.Execute(It.IsAny <IApplicationSettingsRepository>(), It.IsAny <IServiceLogRepository>(), It.IsAny <ActionMessage>(), It.IsAny <IDbTransaction>()), Times.Once);
        }
        public async Task <IActionResult> PutWorkflow(string app, DomainId id, [FromBody] UpdateWorkflowDto request)
        {
            var command = request.ToCommand(id);

            var response = await InvokeCommandAsync(command);

            return(Ok(response));
        }
Exemple #6
0
        public async Task Should_manage_workflows()
        {
            var workflowName = Guid.NewGuid().ToString();

            // STEP 0: Create workflow.
            var createRequest = new AddWorkflowDto
            {
                Name = workflowName
            };

            var workflows_1 = await _.Apps.PostWorkflowAsync(_.AppName, createRequest);

            var workflow_1 = workflows_1.Items.FirstOrDefault(x => x.Name == workflowName);

            Assert.NotNull(workflow_1);
            Assert.NotNull(workflow_1.Name);
            Assert.Equal(3, workflow_1.Steps.Count);


            // STEP 1: Update workflow.
            var updateRequest = new UpdateWorkflowDto
            {
                Initial = "Draft",
                Steps   = new Dictionary <string, WorkflowStepDto>
                {
                    ["Draft"] = new WorkflowStepDto
                    {
                        Transitions = new Dictionary <string, WorkflowTransitionDto>
                        {
                            ["Published"] = new WorkflowTransitionDto()
                        }
                    },
                    ["Published"] = new WorkflowStepDto(),
                },
                Name = workflowName
            };

            var workflows_2 = await _.Apps.PutWorkflowAsync(_.AppName, workflow_1.Id, updateRequest);

            var workflow_2 = workflows_2.Items.FirstOrDefault(x => x.Name == workflowName);

            Assert.NotNull(workflow_2);
            Assert.NotNull(workflow_2.Name);
            Assert.Equal(2, workflow_2.Steps.Count);


            // STEP 2: Delete workflow.
            var workflows_3 = await _.Apps.DeleteWorkflowAsync(_.AppName, workflow_1.Id);

            var workflow_3 = workflows_3.Items.FirstOrDefault(x => x.Name == workflowName);

            // Should not return deleted workflow.
            Assert.Null(workflow_3);
        }
        public static void Validate(this UpdateWorkflowDto dto)
        {
            if (dto.Name == null || dto.Name.Length < WorkflowConstants.MinNameLength || dto.Name.Length > WorkflowConstants.MaxNameLength)
            {
                throw new BadRequestException(ErrorMessages.WorkflowNameError, ErrorCodes.BadRequest);
            }

            if (dto.Description != null && dto.Description.Length > WorkflowConstants.MaxDescriptionLength)
            {
                throw new BadRequestException(ErrorMessages.WorkflowDescriptionLimit, ErrorCodes.BadRequest);
            }
        }
        public async Task UpdateWorkflowAsync_WorkflowNotExistsInDb_ThrowsResourceNotFound()
        {
            // Arrange
            var updateSatus = new UpdateWorkflowDto()
            {
                VersionId = 1, Status = true
            };

            _workflowRepositoryMock
            .Setup(repo => repo.GetWorkflowDetailsAsync(It.IsAny <int>())).ReturnsAsync((SqlWorkflow)null);
            // Act
            await _service.UpdateWorkflowAsync(updateSatus, WorkflowId, SessionUserId);
        }
Exemple #9
0
        public async Task <HttpResponseMessage> UpdateWorkflow(int workflowId, [FromBody] UpdateWorkflowDto workflowDto)
        {
            await _privilegesManager.Demand(Session.UserId, InstanceAdminPrivileges.AccessAllProjectData);

            if (workflowDto != null)
            {
                workflowDto.Name        = workflowDto.Name?.Trim() ?? workflowDto.Name;
                workflowDto.Description = workflowDto.Description?.Trim() ?? workflowDto.Description;
            }
            else
            {
                throw new BadRequestException(ErrorMessages.WorkflowModelIsEmpty, ErrorCodes.BadRequest);
            }

            workflowDto.Validate();

            await _workflowService.UpdateWorkflowAsync(workflowDto, workflowId, Session.UserId);

            return(Request.CreateResponse(HttpStatusCode.NoContent));
        }
        private void MapSchemas(UpdateWorkflowDto workflow, Dictionary <string, string> schemaMap)
        {
            var schemaIds = new List <string>();

            foreach (var schema in workflow.SchemaIds)
            {
                if (!schemaMap.TryGetValue(schema, out var found))
                {
                    log.WriteLine($"Schema {schema} not found.");

                    schemaIds.Add(schema);
                }
                else
                {
                    schemaIds.Add(found);
                }
            }

            workflow.SchemaIds = schemaIds;
        }
        public void Validate_NameIsValid_NoException()
        {
            // arrange
            Exception exception = null;
            var       model     = new UpdateWorkflowDto {
                Name = "L"
            };

            // act
            try
            {
                model.Validate();
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            // assert
            Assert.IsNull(exception);
        }
        public void Validate_NameToLong_ReturnBadRequestException()
        {
            // arrange
            Exception exception = null;
            var       model     = new UpdateWorkflowDto {
                Name = "Lorem ipsum dolor sit ame"
            };                                                                        // 25 symbols - only max 24 is Ok

            // act
            try
            {
                model.Validate();
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            // assert
            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(exception, typeof(BadRequestException));
            Assert.AreEqual(ErrorMessages.WorkflowNameError, exception.Message);
        }
        public void Validate_NameIsEmptyString_BadRequest()
        {
            // arrange
            Exception exception = null;
            var       model     = new UpdateWorkflowDto {
                Name = string.Empty
            };

            // act
            try
            {
                model.Validate();
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            // assert
            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(exception, typeof(BadRequestException));
            Assert.AreEqual(ErrorMessages.WorkflowNameError, exception.Message);
        }
        public async Task Should_update_workflow()
        {
            // STEP 0: Create app.
            await CreateAppAsync();


            // STEP 0: Create workflow.
            var workflow = await CreateAsync();


            // STEP 1: Update workflow.
            var updateRequest = new UpdateWorkflowDto
            {
                Initial = "Draft",
                Steps   = new Dictionary <string, WorkflowStepDto>
                {
                    ["Draft"] = new WorkflowStepDto
                    {
                        Transitions = new Dictionary <string, WorkflowTransitionDto>
                        {
                            ["Published"] = new WorkflowTransitionDto()
                        }
                    },
                    ["Published"] = new WorkflowStepDto(),
                },
                Name = name
            };

            var workflows_2 = await _.Apps.PutWorkflowAsync(appName, workflow.Id, updateRequest);

            var workflow_2 = workflows_2.Items.Find(x => x.Name == name);

            Assert.NotNull(workflow_2);
            Assert.NotNull(workflow_2.Name);
            Assert.Equal(2, workflow_2.Steps.Count);
        }