public Domain.Task.Task PopulateDomainObject(Domain.Task.Task entity, TaskEditDTO dto) { entity.Name = dto.Name; entity.Time = dto.Time; if (entity.User == null) { entity.User = new Domain.User.User(); } entity.User.Id = dto.UserId; return(entity); }
public void ConvertToDomainObjectTest() { var dto = new TaskEditDTO { Name = "test", Time = DateTime.Now, UserId = Guid.NewGuid() }; var mapper = new TaskDtoMapper(); var result = mapper.ConvertToDomainObject(dto); Assert.AreEqual(dto.Name, result.Name); Assert.AreEqual(dto.Time, result.Time); Assert.AreEqual(dto.UserId, result.User.Id); }
public void PopulateDomainObjectTest() { var task = new Domain.Task.Task(); var dto = new TaskEditDTO { Name = "test", Time = DateTime.Now, UserId = Guid.NewGuid() }; var mapper = new TaskDtoMapper(); var result = mapper.PopulateDomainObject(task, dto); Assert.AreEqual(dto.Name, result.Name); Assert.AreEqual(dto.Time, result.Time); Assert.AreEqual(dto.UserId, result.User.Id); }
public HttpResponseMessage Post([FromBody] TaskEditDTO task) { var request = new InsertTaskRequest { TaskProperties = task }; var response = new InsertTaskResponse(); try { response = _taskService.InsertTask(request); } catch (Exception ex) { response.Exception = ex; } return(_responseBuilder.BuildResponse(Request, response)); }
public ResultModel <object> Update(int id, TaskEditDTO model) { ResultModel <object> result = new ResultModel <object>(); try { using (var transaction = _context.Database.BeginTransaction()) { try { var data = _context.Tasks.Where(x => x.Id == id).FirstOrDefault(); if (data != null) { var task = _mapper.Map(model, data); _context.Entry(task).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _context.SaveChanges(); transaction.Commit(); result.SetSuccess("Data successfuly updated"); } else { result.SetSuccess("Data is not found!"); } } catch (Exception ex) { transaction.Rollback(); throw new Exception(ex.ToString()); } } } catch (Exception ex) { result.SetFailed(ex.Message); _logging.WriteErr(ex); } return(result); }
public void PostInvalidTest() { var input = new TaskEditDTO { Time = DateTime.Now, UserId = Guid.NewGuid() }; var expected = new InsertTaskResponse { Result = true, Exception = new ValidationException("name") }; var mockService = new Mock <ITaskService>(); mockService.Setup(x => x.InsertTask(It.IsAny <InsertTaskRequest>())).Returns(expected); var mockRespoonseBuilder = new Mock <IHttpResponseBuilder>(); var controller = new TaskController(mockService.Object, mockRespoonseBuilder.Object) { Request = new HttpRequestMessage(), Configuration = new HttpConfiguration() }; mockRespoonseBuilder.Setup(x => x.BuildResponse(It.IsAny <HttpRequestMessage>(), expected)) .Returns(new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new StringContent(expected.Exception.Message) }); var response = controller.Post(input); bool result; response.TryGetContentValue(out result); Assert.IsFalse(result); Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode); mockService.Verify(x => x.InsertTask(It.IsAny <InsertTaskRequest>()), Times.Once); }
public void PostTest() { var input = new TaskEditDTO { Name = "test", Time = DateTime.Now, UserId = Guid.NewGuid() }; var expected = new InsertTaskResponse { Result = true }; var mockService = new Mock <ITaskService>(); mockService.Setup(x => x.InsertTask(It.IsAny <InsertTaskRequest>())).Returns(expected); var mockRespoonseBuilder = new Mock <IHttpResponseBuilder>(); var controller = new TaskController(mockService.Object, mockRespoonseBuilder.Object) { Request = new HttpRequestMessage(), Configuration = new HttpConfiguration() }; mockRespoonseBuilder.Setup(x => x.BuildResponse(controller.Request, expected)) .Returns(controller.Request.CreateResponse(HttpStatusCode.OK, expected.Result)); var response = controller.Post(input); bool result; response.TryGetContentValue(out result); Assert.IsTrue(result); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); mockService.Verify(x => x.InsertTask(It.IsAny <InsertTaskRequest>()), Times.Once); }
public ActionResult Put(int id, [FromBody] TaskEditDTO model) { return(Ok(_task.Update(id, model))); }
public Domain.Task.Task ConvertToDomainObject(TaskEditDTO dto) { return(PopulateDomainObject(new Domain.Task.Task(), dto)); }