public void Update(UserDetailModel model) { using (var dbContext = dbContextFactory.CreateDbContext()) { var entity = UserMapper.DetailModelToEntity(model); dbContext.Users.Update(entity); dbContext.SaveChanges(); } }
public UserDetailModel Create(UserDetailModel model) { using (var dbContext = dbContextFactory.CreateDbContext()) { var entity = UserMapper.DetailModelToEntity(model); dbContext.Users.Add(entity); dbContext.SaveChanges(); return(UserMapper.EntityToDetailModel(entity)); } }
public void DetailModelToEntity_ShouldBeSame() { var model = new UserDetailModel { Id = Guid.NewGuid(), FirstName = "John", LastName = "Doe", Email = "*****@*****.**" }; var returned = UserMapper.DetailModelToEntity(model); Assert.Equal(model.Id, returned.Id); Assert.Equal(model.FirstName, returned.FirstName); Assert.Equal(model.Email, returned.Email); Assert.Equal(model.ProfilePicture, returned.ProfilePicture); Assert.Equal(model.Nickname, returned.Nickname); Assert.IsType <User>(returned); }
public void UserEntityModelTest() { var userMapper = new UserMapper(); Assert.Null(userMapper.EntityToDetailModel(null)); Assert.Null(userMapper.DetailModelToEntity(null)); Assert.Null(userMapper.EntityToListModel(null)); var UserEntityObject = new UserEntity() { Id = 1, Name = "Jan", Email = "*****@*****.**", Password = "******", }; var UserModelObject = new UserDetailModel() { Id = 1, Name = "Jan", Email = "*****@*****.**", Password = "******", }; var Comment1 = new CommentEntity() { Author = 12, Date = new DateTime(2019, 1, 4), Id = 1, Text = "Testovaci koment" }; var Comment2 = new CommentEntity() { Author = 12, Date = new DateTime(2019, 5, 4), Id = 2, Text = "Testovaci koment cislo 2" }; var CommentModel = new CommentModel() { Author = 12, Date = new DateTime(2019, 5, 4), Id = 2, Text = "Testovaci koment cislo 2" }; var CommentModel1 = new CommentModel() { Author = 12, Date = new DateTime(2019, 1, 4), Id = 1, Text = "Testovaci koment" }; var PostEntity = new PostEntity() { Id = 6, Author = 12, Comments = new Collection <CommentEntity>(), Date = new DateTime(2019, 5, 4), Team = 2, Text = "Post", Title = "Titulok" }; PostEntity.Comments.Add(Comment1); PostEntity.Comments.Add(Comment2); var PostModel = new PostModel() { Id = 6, Author = 12, Comments = new Collection <CommentModel>(), Date = new DateTime(2019, 5, 4), Team = 2, Text = "Post", Title = "Titulok" }; PostModel.Comments.Add(CommentModel1); PostModel.Comments.Add(CommentModel); Assert.Equal(UserModelObject, userMapper.EntityToDetailModel(UserEntityObject)); Assert.Equal(UserEntityObject, userMapper.DetailModelToEntity(UserModelObject)); UserEntityObject.Comments = new Collection <CommentEntity>(); UserModelObject.Comments = new Collection <CommentModel>(); UserEntityObject.Comments.Add(Comment1); UserEntityObject.Comments.Add(Comment2); UserModelObject.Comments.Add(CommentModel1); UserModelObject.Comments.Add(CommentModel); Assert.Equal(UserModelObject, userMapper.EntityToDetailModel(UserEntityObject)); Assert.Equal(UserEntityObject, userMapper.DetailModelToEntity(UserModelObject)); UserModelObject.Posts = new Collection <PostModel>(); UserEntityObject.Posts = new Collection <PostEntity>(); UserEntityObject.Posts.Add(PostEntity); UserModelObject.Posts.Add(PostModel); Assert.Equal(UserModelObject, userMapper.EntityToDetailModel(UserEntityObject)); Assert.Equal(UserEntityObject, userMapper.DetailModelToEntity(UserModelObject)); }