Example #1
0
        public void DetailModelToEntity_ShouldBeEqual()
        {
            var user = new UserDetailModel
            {
                FirstName = "John",
                LastName  = "Doe"
            };

            var model = new CommentDetailModel
            {
                Author = user,
                Id     = Guid.NewGuid(),
                Text   = "This is a comment!"
            };

            var returned = CommentMapper.DetailModelToEntity(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.Image, returned.Picture);
            Assert.Equal(model.Timestamp, returned.Timestamp);

            Assert.IsType <Comment>(returned);
        }
 public void Update(CommentDetailModel model)
 {
     using (var dbContext = dbContextFactory.CreateDbContext())
     {
         var entity = CommentMapper.DetailModelToEntity(model);
         dbContext.Comments.Update(entity);
         dbContext.SaveChanges();
     }
 }
 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));
     }
 }