public void Update(TeamDetailModel model)
 {
     using (var dbContext = dbContextFactory.CreateDbContext())
     {
         var entity = TeamMapper.DetailModelToEntity(model);
         dbContext.Teams.Update(entity);
         dbContext.SaveChanges();
     }
 }
 public TeamDetailModel Create(TeamDetailModel model)
 {
     using (var dbContext = dbContextFactory.CreateDbContext())
     {
         var entity = TeamMapper.DetailModelToEntity(model);
         dbContext.Teams.Add(entity);
         dbContext.SaveChanges();
         return(TeamMapper.EntityToDetailModel(entity));
     }
 }
示例#3
0
        public void DetailModelToEntity_ShouldBeEqual()
        {
            var model = new TeamDetailModel
            {
                Id   = Guid.NewGuid(),
                Name = "Film stars",
            };

            var returned = TeamMapper.DetailModelToEntity(model);

            Assert.Equal(model.Id, returned.Id);
            Assert.Equal(model.Name, returned.Name);

            Assert.IsType <Team>(returned);
        }
示例#4
0
        public void TeamEntityModelTest()
        {
            var teamMapper = new TeamMapper();
            var userMapper = new UserMapper();

            Assert.Null(teamMapper.EntityToDetailModel(null));
            Assert.Null(teamMapper.DetailModelToEntity(null));

            var UserEntityObject = new UserEntity()
            {
                Id       = 4,
                Name     = "Anton",
                Password = "******",
                Email    = "*****@*****.**",
                Comments = new Collection <CommentEntity>(),
                Posts    = new Collection <PostEntity>()
            };

            var TeamEntityObject = new TeamEntity()
            {
                Id     = 2,
                Leader = UserEntityObject.Id,
                Name   = "Team1"
            };


            var UserModelObject = new UserDetailModel()
            {
                Id       = 4,
                Name     = "Anton",
                Password = "******",
                Email    = "*****@*****.**",
                Comments = new Collection <CommentModel>(),
                Posts    = new Collection <PostModel>()
            };

            var TeamModelObject = new TeamDetailModel()
            {
                Id      = 2,
                Leader  = UserModelObject.Id,
                Members = new Collection <UserListModel>(),
                Name    = "Team1"
            };

            Assert.Equal(TeamModelObject, teamMapper.EntityToDetailModel(TeamEntityObject));

            TeamEntityObject.Members = new Collection <TeamUserEntity>();

            TeamModelObject.Members = null;

            Assert.Equal(TeamEntityObject, teamMapper.DetailModelToEntity(TeamModelObject));

            TeamModelObject.Members = new Collection <UserListModel>();

            TeamEntityObject.Members.Add(new TeamUserEntity()
            {
                UserId = UserEntityObject.Id, UserName = UserEntityObject.Name
            });
            TeamModelObject.Members.Add(userMapper.DetailModelToListModel(UserModelObject));

            Assert.Equal(TeamModelObject, teamMapper.EntityToDetailModel(TeamEntityObject));
            Assert.Equal(TeamEntityObject, teamMapper.DetailModelToEntity(TeamModelObject));
        }