Exemplo n.º 1
0
        public void TaskMapper_ToEntity()
        {
            var taskModel = new TaskModel {  id = Guid.NewGuid(), title = "title", description = "description", state = StateTaskModel.InProgress };
            var taskEntity = _taskMapper.ToEntity(taskModel);

            Assert.IsInstanceOfType(taskEntity, typeof(Task));
            Assert.AreEqual(taskModel.id, taskEntity.Id);
            Assert.AreEqual(StateTask.InProgress, taskEntity.State);
            Assert.AreEqual(taskModel.description, taskEntity.Description);
        }
Exemplo n.º 2
0
        public HttpResponseMessage Post(TaskModel task)
        {
            try
            {
                var taskForInsert = _taskMapper.ToEntity(task);
                if(!_tasksService.IsValidTaskForInsert(taskForInsert))
                {
                    return Request.CreateResponse(HttpStatusCode.BadRequest, "Los datos no son correctos.");
                }

                var taskSaved = _tasksService.Save(taskForInsert);
                var taskModel = _taskMapper.ToModel(taskSaved);
                return Request.CreateResponse(HttpStatusCode.OK, taskModel);
            }
            catch (Exception ex)
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError, ex);
            }
        }
Exemplo n.º 3
0
 public Task ToEntity(TaskModel model)
 {
     return AutoMapper.Mapper.Map<Task>(model);
 }