Esempio n. 1
0
        public void GetTasks_maps_entities_to_web_models()
        {
            var taskEntity1 = new Task {
                TaskId = 300
            };
            var taskEntity2 = new Task {
                TaskId = 600
            };
            var task1 = new Models.Task {
                TaskId = taskEntity1.TaskId
            };
            var task2 = new Models.Task {
                TaskId = taskEntity2.TaskId
            };

            var taskEntities = new List <Task> {
                taskEntity1, taskEntity2
            };
            var tasks = new List <Models.Task> {
                task1, task2
            };

            for (var i = 0; i < taskEntities.Count; ++i)
            {
                var index = i;
                _autoMapperMock.Setup(x => x.Map <Models.Task>(taskEntities[index])).Returns(tasks[index]);
            }

            var actualResult = _inquiryProcessor.GetTasks(taskEntities);

            Assert.IsTrue(tasks.SequenceEqual(actualResult));
        }
Esempio n. 2
0
        public void GetTasks_adds_self_link_to_tasks()
        {
            var taskEntity1 = new Task {
                TaskId = 300
            };
            var taskEntity2 = new Task {
                TaskId = 600
            };
            var task1 = new Models.Task {
                TaskId = taskEntity1.TaskId
            };
            var task2 = new Models.Task {
                TaskId = taskEntity2.TaskId
            };

            var taskEntities = new List <Task> {
                taskEntity1, taskEntity2
            };
            var tasks = new List <Models.Task> {
                task1, task2
            };

            for (var i = 0; i < taskEntities.Count; ++i)
            {
                var index = i;
                _autoMapperMock.Setup(x => x.Map <Models.Task>(taskEntities[index])).Returns(tasks[index]);

                _taskLinkServiceMock.Setup(x => x.AddSelfLink(tasks[index])).Verifiable();
            }

            _inquiryProcessor.GetTasks(taskEntities);

            _taskLinkServiceMock.VerifyAll();
        }
Esempio n. 3
0
        public void GetTasks_adds_links()
        {
            var requestInfo = new PagedDataRequest(PageNumber, PageSize);
            var taskEntity  = new Task {
                TaskId = 300
            };
            var queriedItems = new[] { taskEntity };
            var queryResult  = new QueryResult <Task>(queriedItems, queriedItems.Count(), PageSize);

            var task = new Models.Task {
                TaskId = taskEntity.TaskId
            };
            var tasks = new[] { task };

            _allTasksQueryProcessorMock.Setup(x => x.GetTasks(requestInfo)).Returns(queryResult);
            _inquiryProcessor.GetTasksTestDouble = items => items == queriedItems ? tasks : null;

            var linksWereAdded = false;

            _inquiryProcessor.AddLinksToInquiryResponseTestDouble =
                response => linksWereAdded = tasks.SequenceEqual(response.Items)
                                             &&
                                             response.PageCount ==
                                             queryResult.TotalPageCount &&
                                             response.PageNumber == PageNumber &&
                                             response.PageSize == PageSize;

            _inquiryProcessor.GetTasks(requestInfo);

            Assert.IsTrue(linksWereAdded);
        }
        public void AddTask(Task task)
        {
            var taskDal = new DatabaseFirst.Task
            {
                TaskId        = (int)task.TaskId,
                Subject       = task.Subject,
                StartDate     = task.StartDate,
                DueDate       = task.DueDate,
                CompletedDate = task.CompletedDate,
                CreatedDate   = _dateTime.UtcNow,
                Status        = _context.Set <Status>().SingleOrDefault(x => x.Name == "Not Started"),
                User          = _context.Set <User>().SingleOrDefault(x => x.Username == _userSession.Username)
            };

            taskDal = _context.Set <DatabaseFirst.Task>().Add(taskDal);
            _context.SaveChanges();
            task.TaskId      = taskDal.TaskId;
            task.CreatedDate = taskDal.CreatedDate;
            task.Status      = new Entities.Status
            {
                Name     = taskDal.Status.Name,
                Ordinal  = taskDal.Status.Ordinal,
                StatusId = taskDal.Status.StatusId
            };
            task.CreatedBy = new Entities.User
            {
                Firstname = taskDal.User.Firstname,
                Lastname  = taskDal.User.Lastname,
                Username  = taskDal.User.Username,
                UserId    = taskDal.User.UserId
            };
            AddTaskUser(task, taskDal);
        }
 private void AddTaskUser(Task task, DatabaseFirst.Task taskDal)
 {
     if (task.Users != null && task.Users.Any())
     {
         foreach (var user in task.Users)
         {
             var persistedUser = _context.Set <User>().SingleOrDefault(x => x.UserId == user.UserId);
             if (persistedUser == null)
             {
                 throw new ChildObjectNotFoundException("User not found");
             }
             _context.Set <TaskUser>().AddOrUpdate(new TaskUser
             {
                 TaskId = taskDal.TaskId,
                 UserId = (int)user.UserId,
                 ts     = DateTime.Now
             });
         }
     }
 }
Esempio n. 6
0
        public void GetTasks_returns_correct_result()
        {
            var requestInfo = new PagedDataRequest(PageNumber, PageSize);
            var taskEntity  = new Task {
                TaskId = 300
            };
            var queriedItems = new[] { taskEntity };
            var queryResult  = new QueryResult <Task>(queriedItems, queriedItems.Count(), PageSize);
            var task         = new Models.Task {
                TaskId = taskEntity.TaskId
            };
            var tasks = new[] { task };

            _allTasksQueryProcessorMock.Setup(x => x.GetTasks(requestInfo)).Returns(queryResult);
            _inquiryProcessor.GetTasksTestDouble = items => items == queriedItems ? tasks : null;
            var actualResult = _inquiryProcessor.GetTasks(requestInfo);

            Assert.IsTrue(tasks.SequenceEqual(actualResult.Items), "Incorrect Items in result");
            Assert.AreEqual(queryResult.TotalPageCount, actualResult.PageCount, "Incorrect PageCount in result");
            Assert.AreEqual(PageNumber, actualResult.PageNumber, "Incorrect PageNumber in result");
            Assert.AreEqual(PageSize, actualResult.PageSize, "Incorrect PageSize in result");
        }
 public void GetTasks_returns_correct_result()
 {
     var requestInfo = new PagedDataRequest(PageNumber, PageSize);
     var taskEntity = new Task {TaskId = 300};
     var queriedItems = new[] {taskEntity};
     var queryResult = new QueryResult<Task>(queriedItems, queriedItems.Count(), PageSize);
     var task = new Models.Task {TaskId = taskEntity.TaskId};
     var tasks = new[] {task};
     _allTasksQueryProcessorMock.Setup(x => x.GetTasks(requestInfo)).Returns(queryResult);
     _inquiryProcessor.GetTasksTestDouble = items => items == queriedItems ? tasks : null;
     var actualResult = _inquiryProcessor.GetTasks(requestInfo);
     Assert.IsTrue(tasks.SequenceEqual(actualResult.Items), "Incorrect Items in result");
     Assert.AreEqual(queryResult.TotalPageCount, actualResult.PageCount, "Incorrect PageCount in result");
     Assert.AreEqual(PageNumber, actualResult.PageNumber, "Incorrect PageNumber in result");
     Assert.AreEqual(PageSize, actualResult.PageSize, "Incorrect PageSize in result");
 }
 public void GetTasks_maps_entities_to_web_models()
 {
     var taskEntity1 = new Task {TaskId = 300};
     var taskEntity2 = new Task {TaskId = 600};
     var task1 = new Models.Task {TaskId = taskEntity1.TaskId};
     var task2 = new Models.Task {TaskId = taskEntity2.TaskId};
     var taskEntities = new List<Task> {taskEntity1, taskEntity2};
     var tasks = new List<Models.Task> {task1, task2};
     for (var i = 0; i < taskEntities.Count; ++i)
     {
         var index = i;
         _autoMapperMock.Setup(x => x.Map<Models.Task>(taskEntities[index])).Returns(tasks[index]);
     }
     var actualResult = _inquiryProcessor.GetTasks(taskEntities);
     Assert.IsTrue(tasks.SequenceEqual(actualResult));
 }
 public void GetTasks_adds_self_link_to_tasks()
 {
     var taskEntity1 = new Task {TaskId = 300};
     var taskEntity2 = new Task {TaskId = 600};
     var task1 = new Models.Task {TaskId = taskEntity1.TaskId};
     var task2 = new Models.Task {TaskId = taskEntity2.TaskId};
     var taskEntities = new List<Task> {taskEntity1, taskEntity2};
     var tasks = new List<Models.Task> {task1, task2};
     for (var i = 0; i < taskEntities.Count; ++i)
     {
         var index = i;
         _autoMapperMock.Setup(x => x.Map<Models.Task>(taskEntities[index])).Returns(tasks[index]);
         _taskLinkServiceMock.Setup(x => x.AddSelfLink(tasks[index])).Verifiable();
     }
     _inquiryProcessor.GetTasks(taskEntities);
     _taskLinkServiceMock.VerifyAll();
 }
 public void GetTasks_adds_links()
 {
     var requestInfo = new PagedDataRequest(PageNumber, PageSize);
     var taskEntity = new Task {TaskId = 300};
     var queriedItems = new[] {taskEntity};
     var queryResult = new QueryResult<Task>(queriedItems, queriedItems.Count(), PageSize);
     var task = new Models.Task {TaskId = taskEntity.TaskId};
     var tasks = new[] {task};
     _allTasksQueryProcessorMock.Setup(x => x.GetTasks(requestInfo)).Returns(queryResult);
     _inquiryProcessor.GetTasksTestDouble = items => items == queriedItems ? tasks : null;
     var linksWereAdded = false;
     _inquiryProcessor.AddLinksToInquiryResponseTestDouble =
         response => linksWereAdded = tasks.SequenceEqual(response.Items)
                                      && response.PageCount == queryResult.TotalPageCount
                                      && response.PageNumber == PageNumber
                                      && response.PageSize == PageSize;
     _inquiryProcessor.GetTasks(requestInfo);
     Assert.IsTrue(linksWereAdded);
 }