public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var item = checkpointService.Get(id); if (item != null) { return(PartialView(item)); } return(HttpNotFound()); }
public void Get() { //Arrange unitWorkMoq.Setup(x => x.Checkpoint.Get(1)).Returns(itemsSimple[0]); unitWorkMoq.Setup(x => x.Checkpoint.Get(2)).Returns(itemsSimple[0]); unitWorkMoq.Setup(x => x.Type.Get(1)).Returns(itemsType[0]); unitWorkMoq.Setup(x => x.Type.Get(2)).Returns(itemsType[1]); unitWorkMoq.Setup(x => x.Type.Get(3)).Returns(itemsType[2]); unitWorkMoq.Setup(x => x.CheckpointAdmission.GetAll()).Returns(itemsCheckpointAdmission); unitWorkMoq.Setup(x => x.Admission.GetAll()).Returns(itemsAdmission); //Act var result = serviceMock.Get(id); //Assert Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(CheckpointDTO)); Assert.IsNotNull(result.ID); Assert.IsNotNull(result.IP); Assert.IsNotNull(result.Campus); Assert.IsNotNull(result.Row); Assert.IsNotNull(result.Description); Assert.IsNotNull(result.Status); Assert.IsNotNull(result.Type); Assert.IsNotNull(result.Admissions); Assert.AreEqual(id, result.ID); Assert.IsTrue(result.Admissions.ToList().Count > 0); }
// GET api/checkpoints/5 /// <summary> /// Gets a <see cref="CheckpointDTO"/> object from the repository. /// </summary> /// <param name="id">The ID of <see cref="CheckpointDTO"/>.</param> /// <returns>The <see cref="CheckpointDTO"/> with the given ID.</returns> public IHttpActionResult Get(int id) { CheckpointDTO item = service.Get(id); if (item != null) { return(Ok(item)); } else { return(NotFound()); } }