Beispiel #1
0
 // POST: api/parentTask/update
 public IHttpActionResult Update(ParentTaskDto task)
 {
     return(Try(() =>
     {
         return Ok(_taskFacade.Update(task));
     }));
 }
        public void Update_ShouldUpdateCorrectParentTask()
        {
            //arrange
            var testTasks = GetTestTasks();
            var parentTaskDtoToBeUpdated = new ParentTaskDto()
            {
                Id   = 2,
                Name = "Name_updated"
            };

            var oldTask = testTasks.First(u => u.Id == parentTaskDtoToBeUpdated.Id);

            var mockParentTaskRepository = new Mock <IParentTaskRepository>().Object;

            Mock.Get <IParentTaskRepository>(mockParentTaskRepository).Setup(r => r.Get(parentTaskDtoToBeUpdated.Id)).Returns(oldTask);

            var taskFacade     = new ParentTaskFacade(mockParentTaskRepository);
            var taskController = new ParentTaskController(taskFacade);

            //act
            var result = taskController.Update(parentTaskDtoToBeUpdated) as OkNegotiatedContentResult <ParentTaskDto>;

            //assert
            Assert.AreEqual(parentTaskDtoToBeUpdated.Name, result.Content.Name);
        }
Beispiel #3
0
        /// <summary>
        /// either create or update provided task
        /// </summary>
        /// <param name="taskDto"></param>
        /// <returns></returns>
        public ParentTaskDto Update(ParentTaskDto taskDto)
        {
            var task = _taskRepository.Get(taskDto.Id);

            if (task == null)
            {
                //create Task
                task = Mapper.Map <ParentTask>(taskDto);
                _taskRepository.Add(task);
            }
            else
            {
                //update task
                task.Name = taskDto.Name;
            }
            _taskRepository.SaveChanges();

            return(taskDto);
        }
        public void Update_ShouldAddNewparentTask()
        {
            //arrange
            var testTasks  = GetTestTasks();
            var newTaskDto = new ParentTaskDto()
            {
                Name = "Name_Mocked",
            };
            var newparentTask = Mapper.Map <ParentTask>(newTaskDto);

            var mockParentTaskRepository = new Mock <IParentTaskRepository>().Object;

            Mock.Get <IParentTaskRepository>(mockParentTaskRepository).Setup(r => r.Add(newparentTask)).Returns(newparentTask);

            var taskFacade     = new ParentTaskFacade(mockParentTaskRepository);
            var taskController = new ParentTaskController(taskFacade);

            //act
            var result = taskController.Update(newTaskDto) as OkNegotiatedContentResult <ParentTaskDto>;

            //assert
            Assert.AreEqual(newTaskDto.Name, result.Content.Name);
        }