public void TestGetPerson() { ValuesController control = new ValuesController(); var erg = (control.GetById(3) as ObjectResult).Value; Assert.IsNotNull(erg); }
public async Task GetById_InvalidId_ReturnsNotFound() { // arrange var controller = new ValuesController(_valueService) { ControllerContext = new ControllerContext() { HttpContext = _contextMock.Object } }; // act var result = await controller.GetById(5); // assert Assert.IsInstanceOfType(result, typeof(NotFoundResult)); Assert.IsTrue(controller.Response.Headers["x-status-reason"].ToString() == "No resource was found with the unique identifier '5'."); }
public async Task GetById_ValidId_ReturnsOk() { // arrange var controller = new ValuesController(_valueService) { ControllerContext = new ControllerContext() { HttpContext = _contextMock.Object } }; // act var result = await controller.GetById(1); // assert Assert.IsInstanceOfType(result, typeof(OkObjectResult)); Assert.IsInstanceOfType((result as OkObjectResult).Value, typeof(string)); Assert.AreEqual(1, JsonConvert.DeserializeObject <ValueModel>((result as OkObjectResult).Value.ToString()).Id); }