Exemplo n.º 1
0
        public void Can_Get_Populated_Instance(int taskCount, int lastGroupId)
        {
            IContent node = Scaffold.Node(ApplicationContext.Current.Services.ContentService);

            Guid guid = Guid.NewGuid();

            WorkflowInstancePoco instance = Scaffold.Instance(guid, (int)WorkflowType.Publish, node.Id);

            _service.InsertInstance(instance);
            for (var i = 1; i <= taskCount; i += 1)
            {
                _tasksService.InsertTask(Scaffold.Task(guid, DateTime.Now,
                                                       i < taskCount ? i : lastGroupId,
                                                       i,
                                                       i < taskCount ? 1 : 3));
            }

            // this has groups, tasks, everything. Or it should.
            WorkflowInstancePoco populatedInstance = _service.GetPopulatedInstance(guid);

            Assert.Equal(taskCount, populatedInstance.TaskInstances.Count);
            Assert.Equal(0, populatedInstance.TotalSteps);                                        // this shouldn't be set yet
            Assert.Equal(lastGroupId, populatedInstance.TaskInstances.First().UserGroup.GroupId); // tasks are descending by id
            Assert.Equal(WorkflowStatus.PendingApproval, populatedInstance.WorkflowStatus);
        }
        public void Can_Get_Pending_Workflow_Tasks()
        {
            List <WorkflowTaskViewModel> result = _service.GetPendingTasks(new List <int>
            {
                (int)TaskStatus.PendingApproval
            }, 10, 1);

            Assert.NotNull(result);
            Assert.Empty(result);

            var i = 0;

            while (i < 5)
            {
                IContent node = Scaffold.Node(_contentService);

                Guid guid = Guid.NewGuid();
                _instancesService.InsertInstance(Scaffold.Instance(guid, 1, node.Id));

                _service.InsertTask(Scaffold.Task(guid));
                i += 1;
            }

            List <WorkflowTaskViewModel> result2 = _service.GetPendingTasks(new List <int>
            {
                (int)TaskStatus.PendingApproval
            }, 10, 1);

            Assert.NotNull(result2);
            Assert.Equal(i, result2.Count);
        }
Exemplo n.º 3
0
        public void Can_Generate_Preview()
        {
            Scaffold.ContentType(ApplicationContext.Current.Services.ContentTypeService);
            IContent node = Scaffold.Node(ApplicationContext.Current.Services.ContentService);
            Guid     guid = Guid.NewGuid();

            _instancesService.InsertInstance(Scaffold.Instance(guid, 0, node.Id));

            _previewService.Generate(node.Id, 0, guid);
        }
Exemplo n.º 4
0
        public void Can_Get_By_Guid()
        {
            var guid = Guid.NewGuid();

            _service.InsertInstance(Scaffold.Instance(guid, 1));

            WorkflowInstancePoco instance = _service.GetByGuid(guid);

            Assert.NotNull(instance);
            Assert.Equal(guid, instance.Guid);
        }
Exemplo n.º 5
0
        public void Can_Get_By_NodeId()
        {
            const int nodeId = 1075;

            _service.InsertInstance(Scaffold.Instance(Guid.NewGuid(), 1, nodeId));

            List <WorkflowInstanceViewModel> instances = _service.GetByNodeId(nodeId, 1, 10);

            Assert.NotNull(instances);
            Assert.Equal(nodeId, instances.First().NodeId);
        }
Exemplo n.º 6
0
        public async void Cannot_Validate_Request_When_No_Tasks()
        {
            Scaffold.Config();

            Guid guid = Guid.NewGuid();

            _instancesService.InsertInstance(Scaffold.Instance(guid, 1, 1089));

            bool isValid = await _previewService.Validate(1089, 99, 6456, guid);

            Assert.False(isValid);
        }
Exemplo n.º 7
0
        public async void Cannot_Validate_Request_When_No_Tasks()
        {
            Guid guid = Guid.NewGuid();

            const int userId = 46;
            const int nodeId = 34904;

            _instancesService.InsertInstance(Scaffold.Instance(guid, 1, nodeId));

            bool isValid = await _previewService.Validate(nodeId, userId, 6456, guid);

            Assert.False(isValid);
        }
        public void Can_Get_Tasks_With_Group_By_Instance_Guid()
        {
            Guid guid = Guid.NewGuid();

            _instancesService.InsertInstance(Scaffold.Instance(guid, 1));
            _service.InsertTask(Scaffold.Task(guid));

            List <WorkflowTaskPoco> result = _service.GetTasksWithGroupByInstanceGuid(guid);

            Assert.NotNull(result);
            Assert.Single(result);
            Assert.Equal(1, result[0].GroupId); // same as default in scaffold.task
        }
        public void Can_Get_Tasks_By_Node_Id()
        {
            const int nodeId = 1055;

            Guid guid = Guid.NewGuid();

            _instancesService.InsertInstance(Scaffold.Instance(guid, 1, nodeId));
            _service.InsertTask(Scaffold.Task(guid, DateTime.Now.AddDays(-1), 3, 1, 1));
            _service.InsertTask(Scaffold.Task(guid, DateTime.Now, 3, 3));

            List <WorkflowTaskPoco> result = _service.GetTasksByNodeId(nodeId);

            Assert.NotNull(result);
            Assert.Equal(2, result.Count);
        }
Exemplo n.º 10
0
        public async void Cannot_Validate_Request_When_Last_Task_Not_Pending()
        {
            Scaffold.Config();

            Guid guid = Guid.NewGuid();

            WorkflowTaskInstancePoco task = Scaffold.Task(guid, status: (int)TaskStatus.NotRequired);

            _tasksService.InsertTask(task);
            _instancesService.InsertInstance(Scaffold.Instance(guid, 1, 1089));

            bool isValid = await _previewService.Validate(1089, 0, task.Id, guid);

            Assert.False(isValid);
        }
Exemplo n.º 11
0
        public void Can_Update_Instance()
        {
            Guid         guid    = Guid.NewGuid();
            const string comment = "This here is an update";

            _service.InsertInstance(Scaffold.Instance(guid, 1));

            WorkflowInstancePoco instance = _service.GetByGuid(guid);

            instance.AuthorComment = comment;

            _service.UpdateInstance(instance);
            WorkflowInstancePoco updatedInstance = _service.GetByGuid(guid);

            Assert.Equal(comment, updatedInstance.AuthorComment);
        }
        public void Can_Get_Tasks_By_Group_Id()
        {
            IContent node = Scaffold.Node(_contentService);

            Guid guid = Guid.NewGuid();

            _instancesService.InsertInstance(Scaffold.Instance(guid, 1, node.Id));

            _service.InsertTask(Scaffold.Task(guid, DateTime.Now.AddDays(-1), 3, 1, 1));
            _service.InsertTask(Scaffold.Task(guid, DateTime.Now, 3, 3));

            List <WorkflowTaskViewModel> result = _service.GetAllGroupTasks(3, 10, 1);

            Assert.NotNull(result);
            Assert.Equal(2, result.Count);
        }
Exemplo n.º 13
0
        public async void Can_Get_Paged_Node_Tasks()
        {
            // get an error if the node doesn't exist
            //object response = await _tasksController.GetNodeTasks(666, -1, -1).GetContent();
            //Assert.Equal("NullReferenceException", (string)response.Get("ExceptionType"));
            //Assert.Equal(MagicStrings.ErrorGettingPendingTasksForNode.Replace("{id}", "666"), (string)response.Get("ExceptionMessage"));

            Scaffold.ContentType(_contentTypeService);
            IContent node = Scaffold.Node(_contentService);

            Scaffold.Config();

            Guid guid = Guid.NewGuid();

            _instancesService.InsertInstance(Scaffold.Instance(guid, 1, node.Id));
            _tasksService.InsertTask(Scaffold.Task(guid));
            _tasksService.InsertTask(Scaffold.Task(guid));
            _tasksService.InsertTask(Scaffold.Task(guid));

            // needs flow or function exits
            Dictionary <int, List <UserGroupPermissionsPoco> > config = Scaffold.Permissions(node.Id, 3, 2);

            _configService.UpdateNodeConfig(config);

            JObject content = await _tasksController.GetNodeTasks(node.Id, 10, 1).GetContent();

            Assert.Equal(1, content.Value <int>("totalPages"));
            Assert.Equal(10, content.Value <int>("count"));
            Assert.Equal(3, content.Value <JArray>("items").Count);

            // when 3 tasks, 1 per page, page 2 should be 1 item
            content = await _tasksController.GetNodeTasks(node.Id, 1, 2).GetContent();

            Assert.Equal(3, content.Value <int>("totalPages"));
            Assert.Equal(1, content.Value <int>("count"));
            Assert.Single(content.Value <JArray>("items"));

            // when 5 tasks, and 2 per page, page 2 should be 2 items
            _tasksService.InsertTask(Scaffold.Task(guid));
            _tasksService.InsertTask(Scaffold.Task(guid));

            content = await _tasksController.GetNodeTasks(node.Id, 2, 2).GetContent();

            Assert.Equal(3, content.Value <int>("totalPages"));
            Assert.Equal(2, content.Value <int>("count"));
            Assert.Equal(2, content.Value <JArray>("items").Count);
        }
        public void Can_Count_User_Tasks()
        {
            Guid guid = Guid.NewGuid();

            _instancesService.InsertInstance(Scaffold.Instance(guid, 1));
            _service.InsertTask(Scaffold.Task(guid));

            // status 1 is approved, there are none
            List <WorkflowTaskPoco> result = _service.GetTaskSubmissionsForUser(0, new[] { 1 });

            Assert.NotNull(result);
            Assert.Empty(result);

            // status 3 is pending approval, there should be one
            result = _service.GetTaskSubmissionsForUser(0, new[] { 3 });

            Assert.NotNull(result);
            Assert.Single(result);
        }
Exemplo n.º 15
0
        public async void Cannot_Validate_Request_When_Last_Task_Not_Pending()
        {
            Guid guid = Guid.NewGuid();

            const int userId = 446;
            const int nodeId = 3456;

            UserGroupPoco group = await AddGroupWithPermissionAndUser(userId, nodeId);

            // create a task on an instance
            WorkflowTaskPoco task = Scaffold.Task(guid, groupId: group.GroupId, status: (int)TaskStatus.NotRequired);

            _tasksService.InsertTask(task);
            _instancesService.InsertInstance(Scaffold.Instance(guid, 1, nodeId));

            bool isValid = await _previewService.Validate(nodeId, userId, task.Id, guid);

            Assert.False(isValid);
        }
Exemplo n.º 16
0
        public async void Can_Validate_Request()
        {
            Guid guid = Guid.NewGuid();

            const int userId = 11;
            const int nodeId = 1089;

            UserGroupPoco group = await AddGroupWithPermissionAndUser(userId, nodeId);

            // create a task on an instance
            WorkflowTaskPoco task = Scaffold.Task(guid, groupId: group.GroupId);

            _tasksService.InsertTask(task);
            _instancesService.InsertInstance(Scaffold.Instance(guid, 1, nodeId));

            // is valid when the user is in the group responsible for the task with the given id
            // and the task belongs to the given instance by guid
            // and both the task and instance are related to the given node id
            bool isValid = await _previewService.Validate(nodeId, userId, task.Id, guid);

            Assert.True(isValid);

            // invalid user id
            isValid = await _previewService.Validate(nodeId, 99, task.Id, guid);

            Assert.False(isValid);

            // invalid task id
            isValid = await _previewService.Validate(nodeId, userId, 11111, guid);

            Assert.False(isValid);

            // invalid guid
            isValid = await _previewService.Validate(nodeId, userId, task.Id, Guid.NewGuid());

            Assert.False(isValid);

            // invalid node id
            isValid = await _previewService.Validate(43535, userId, task.Id, guid);

            Assert.False(isValid);
        }
        public void Can_Get_Task_By_id()
        {
            IContent root = Scaffold.Node(_contentService);

            Guid guid = Guid.NewGuid();

            _instancesService.InsertInstance(Scaffold.Instance(guid, 1, root.Id));
            _service.InsertTask(Scaffold.Task(guid));

            List <WorkflowTaskViewModel> tasks = _service.GetPendingTasks(new List <int>
            {
                (int)TaskStatus.PendingApproval
            }, 10, 1);
            int id = tasks.First().TaskId;

            WorkflowTaskViewModel taskViewModel = _service.GetTask(id);

            Assert.NotNull(taskViewModel);
            Assert.Equal(id, taskViewModel.TaskId);
        }
        public async void Can_Get_Node_Pending_Tasks()
        {
            Scaffold.ContentType(_contentTypeService);
            IContent node = Scaffold.Node(_contentService);

            Scaffold.Config();

            Guid guid = Guid.NewGuid();

            _instancesService.InsertInstance(Scaffold.Instance(guid, 1, node.Id));
            _tasksService.InsertTask(Scaffold.Task(guid));

            // needs flow or function exits
            Dictionary <int, List <UserGroupPermissionsPoco> > config = Scaffold.Permissions(node.Id, 3, 0);

            _configService.UpdateNodeConfig(config);

            JObject content = await _tasksController.GetNodePendingTasks(node.Id).GetContent();

            Assert.Single(content.Value <JArray>("items"));
        }
Exemplo n.º 19
0
        public async void Can_Validate_Request()
        {
            Scaffold.Config();

            Guid guid = Guid.NewGuid();

            WorkflowTaskInstancePoco task = Scaffold.Task(guid);

            _tasksService.InsertTask(task);
            _instancesService.InsertInstance(Scaffold.Instance(guid, 1, 1089));

            // is valid when the user is in the group responsible for the task with the given id
            // and the task belongs to the given instance by guid
            // and both the task and instance are related to the given node id
            bool isValid = await _previewService.Validate(1089, 0, task.Id, guid);

            Assert.True(isValid);

            isValid = await _previewService.Validate(1089, 99, 6456, guid);

            Assert.False(isValid);
        }
Exemplo n.º 20
0
        public void Can_Get_Pending_Workflow_Tasks()
        {
            Scaffold.Config();
            const int nodeId = 1055;

            List <WorkflowTask> result = _service.GetPendingTasks(new[] { 1, 2, 3 }, 10, 1);

            Assert.NotNull(result);
            Assert.Empty(result);

            Guid guid = Guid.NewGuid();

            _instancesService.InsertInstance(Scaffold.Instance(guid, 1, nodeId));
            _service.InsertTask(Scaffold.Task(guid, DateTime.Now.AddDays(-4), 2, 1, 1));
            _service.InsertTask(Scaffold.Task(guid, DateTime.Now.AddDays(-1), 3, 2, 1));
            _service.InsertTask(Scaffold.Task(guid, DateTime.Now, 3, 3));

            result = _service.GetPendingTasks(new[] { 1, 2, 3 }, 10, 1);

            Assert.NotNull(result);
            Assert.Equal(3, result.Count);
        }
        public void Can_Get_Paged_Filtered_Tasks()
        {
            IContent node = Scaffold.Node(_contentService);

            Guid guid = Guid.NewGuid();

            _instancesService.InsertInstance(Scaffold.Instance(guid, 1, node.Id));

            _service.InsertTask(Scaffold.Task(guid));
            _service.InsertTask(Scaffold.Task(guid));
            _service.InsertTask(Scaffold.Task(guid));
            _service.InsertTask(Scaffold.Task(guid));
            _service.InsertTask(Scaffold.Task(guid, DateTime.Now, 2, 1, 1));

            List <WorkflowTaskViewModel> tasks = _service.GetFilteredPagedTasksForDateRange(DateTime.Now.AddDays(-2), 2, 1);

            Assert.NotEmpty(tasks);
            Assert.Equal(2, tasks.Count);

            tasks = _service.GetFilteredPagedTasksForDateRange(DateTime.Now.AddDays(-2), 1, 1, "1");

            Assert.NotEmpty(tasks);
            Assert.Single(tasks);
        }