public void EntityToDetailModel_ShouldBeEqual() { var user = new User() { FirstName = "John", LastName = "Doe" }; var model = new Comment() { Author = user, Id = Guid.NewGuid(), Text = "This is a comment!" }; var returned = CommentMapper.EntityToDetailModel(model); Assert.Equal(model.Author.FirstName, returned.Author.FirstName); Assert.Equal(model.Author.LastName, returned.Author.LastName); Assert.Equal(model.Id, returned.Id); Assert.Equal(model.Text, returned.Text); Assert.Equal(model.Picture, returned.Image); Assert.Equal(model.Timestamp, returned.Timestamp); Assert.IsType <CommentDetailModel>(returned); }
public CommentDetailModel GetById(Guid id) { using (var dbContext = dbContextFactory.CreateDbContext()) { var entity = dbContext.Comments.First(t => t.Id == id); return(CommentMapper.EntityToDetailModel(entity)); } }
public CommentDetailModel Create(CommentDetailModel model) { using (var dbContext = dbContextFactory.CreateDbContext()) { var entity = CommentMapper.DetailModelToEntity(model); dbContext.Comments.Add(entity); dbContext.SaveChanges(); return(CommentMapper.EntityToDetailModel(entity)); } }