Exemplo n.º 1
0
        public void Add(string name, int idDocumentTemplate, IDictionary <Tuple <string, int>, IList <int> > paths)
        {
            var template = new DocumentTaskTemplate {
                Name = name, IdDocumentTemplate = idDocumentTemplate
            };

            foreach (var path in paths)
            {
                var taskType = new DocumentTaskType {
                    Name = path.Key.Item1, DaysLimit = path.Key.Item2
                };
                for (var i = path.Value.Count - 1; i >= 0; i--)
                {
                    taskType.Paths.Add(new DocumentTaskTypePath
                    {
                        Index       = i,
                        IdUserGroup = path.Value[i],
                        NextPath    = taskType.Paths.Any() ? taskType.Paths.ElementAt(path.Value.Count - i - 2) : null
                    });
                }
                template.DocumentTaskTypes.Add(taskType);
            }

            dbContext.DocumentTaskTemplates.Add(template);
        }
Exemplo n.º 2
0
        public async Task Can_Add_Document_Task()
        {
            var dbContextOptions = CreateNewContextOptions();

            var user     = new User();
            var taskType = new DocumentTaskType {
                Paths = new List <DocumentTaskTypePath> {
                    new DocumentTaskTypePath(), new DocumentTaskTypePath()
                }
            };

            using (var context = new ApplicationDbContext(dbContextOptions))
            {
                context.Users.Add(user);
                context.DocumentTaskTypes.Add(taskType);
                context.Documents.AddRange(new Document(), new Document(), new Document());

                await context.SaveChangesAsync();
            }

            using (var context = new ApplicationDbContext(dbContextOptions))
            {
                var service = new DocumentTasksService(context);

                await service.Add("UserId", 1, new List <int> {
                    1, 2, 3
                });

                await context.SaveChangesAsync();
            }

            using (var context = new ApplicationDbContext(dbContextOptions))
            {
                var task = await context.DocumentTasks.Include(it => it.Documents).Include(it => it.DocumentTaskStates).FirstAsync();

                Assert.NotEqual(DateTime.MinValue, task.DateAdded);
                Assert.NotEqual(DateTime.MinValue, task.LastModified);
                Assert.Equal("UserId", task.UserId);
                Assert.Equal(1, task.IdDocumentTaskType);
                Assert.Equal(3, task.Documents.Count);

                var state = task.DocumentTaskStates.Last();
                Assert.NotEqual(DateTime.MinValue, state.StateDate);
                Assert.Equal(DocumentTaskStatus.RequireAction, state.DocumentTaskStatus);
                Assert.Equal(1, state.IdDocumentTaskTypePath.Value);
            }
        }