public Target Update(Target item) { Repo.Update(item); Unit.SaveChanges(); return item; }
// PUT api/Activity/5 public IHttpActionResult Put(Target item) { if (!ModelState.IsValid) { return BadRequest(ModelState); } try { return Ok(Logic.Update(item)); } catch (DbUpdateConcurrencyException) { if (!Logic.Exists(item.Id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public void TargetRepository() { Mock<IDbSetFactory> factory = new Mock<IDbSetFactory>(); Mock<DbSet<Target>> dbSet = new Mock<DbSet<Target>>(); factory.Setup(m => m.CreateDbSet<Target>()).Returns(dbSet.Object); TargetRepository repo = new TargetRepository(factory.Object); var Target = new Target(); var sequence = new MockSequence(); dbSet.InSequence(sequence).Setup(e => e.Add(Target)); dbSet.InSequence(sequence).Setup(e => e.Find(Target.Id)); dbSet.InSequence(sequence).Setup(e => e.Find(Target.Id)); dbSet.InSequence(sequence).Setup(e => e.Find(Target.Id)); repo.Create(Target); repo.Get(Target.Id); repo.Update(Target); repo.Delete(Target.Id); }
public void TargetLogic() { Mock<IUnitOfWork> uow = new Mock<IUnitOfWork>(); Mock<ITargetRepository> repo = new Mock<ITargetRepository>(); TargetLogic logic = new TargetLogic(uow.Object, repo.Object); var target = new Target(); var sequence = new MockSequence(); repo.InSequence(sequence).Setup(r => r.Create(target)); repo.InSequence(sequence).Setup(r => r.Update(target)); repo.InSequence(sequence).Setup(r => r.Get(target.Id)); repo.InSequence(sequence).Setup(r => r.Delete(target.Id)); logic.Create(target); logic.Update(target); logic.Get(target.Id); logic.Delete(target.Id); }
public IHttpActionResult Post(Target item) { Target Created = Logic.Create(item); return Ok(Created); }