public Attainment Update(Attainment item) { Repo.Update(item); Unit.SaveChanges(); return item; }
public void AttainmentRepository() { Mock<IDbSetFactory> factory = new Mock<IDbSetFactory>(); Mock<DbSet<Attainment>> dbSet = new Mock<DbSet<Attainment>>(); factory.Setup(m => m.CreateDbSet<Attainment>()).Returns(dbSet.Object); AttainmentRepository repo = new AttainmentRepository(factory.Object); var attainment = new Attainment(); var sequence = new MockSequence(); dbSet.InSequence(sequence).Setup(e => e.Add(attainment)); dbSet.InSequence(sequence).Setup(e => e.Find(attainment.Id)); dbSet.InSequence(sequence).Setup(e => e.Find(attainment.Id)); dbSet.InSequence(sequence).Setup(e => e.Find(attainment.Id)); repo.Create(attainment); repo.Get(attainment.Id); repo.Update(attainment); repo.Delete(attainment.Id); }
public void AttainmentLogic() { Mock<IUnitOfWork> uow = new Mock<IUnitOfWork>(); Mock<IAttainmentRepository> repo = new Mock<IAttainmentRepository>(); Mock<IBadgeRepository> badgeRepo = new Mock<IBadgeRepository>(); Mock<IActivityRepository> activityRepo = new Mock<IActivityRepository>(); Mock<ITargetRepository> targetRepo = new Mock<ITargetRepository>(); Mock<ITeamLogic> teamLogic = new Mock<ITeamLogic>(); AttainmentLogic logic = new AttainmentLogic(uow.Object, repo.Object, badgeRepo.Object, activityRepo.Object, targetRepo.Object, teamLogic.Object); var attainment = new Attainment(); var sequence = new MockSequence(); repo.InSequence(sequence).Setup(r => r.Create(attainment)); repo.InSequence(sequence).Setup(r => r.Update(attainment)); repo.InSequence(sequence).Setup(r => r.Get(attainment.Id)); repo.InSequence(sequence).Setup(r => r.Delete(attainment.Id)); logic.Create(attainment); logic.Update(attainment); logic.Get(attainment.Id); logic.Delete(attainment.Id); }
// PUT api/Activity/5 public IHttpActionResult Put(Attainment item) { if (!ModelState.IsValid) { return BadRequest(ModelState); } try { return Ok(Logic.Update(item)); } catch (DbUpdateConcurrencyException) { if (!Logic.Exists(item.Id)) { return NotFound(); } else { throw; } } }
public IHttpActionResult Post(Attainment item) { Attainment Created = Logic.Create(item); return Ok(Created); }