public void GetRecord_WithValidModelAndInvalidId_Returns_NotFoundResult() { // Arrange var recordServiceMock = new Mock <IRecordService>(); recordServiceMock.Setup(service => service .GetRecordByIdAsync(It.IsAny <int>())) .Returns(Task.FromResult(GetNullRecord())); var loggerMock = new Mock <ILogger <RecordsController> >(); var controller = new RecordsController(recordServiceMock.Object, loggerMock.Object); var id = 2; // Act var result = controller.GetRecord(id).GetAwaiter().GetResult(); // Assert var notFoundObjectResult = Assert.IsType <NotFoundObjectResult>(result); Assert.IsAssignableFrom <int>(notFoundObjectResult.Value); }
public void GetRecord_WithInvalidModel_Returns_BadRequestResult() { // Arrange var recordServiceMock = new Mock <IRecordService>(); recordServiceMock.Setup(service => service .GetRecordByIdAsync(It.IsAny <int>())) .Returns(Task.FromResult(GetRecord())); var loggerMock = new Mock <ILogger <RecordsController> >(); var controller = new RecordsController(recordServiceMock.Object, loggerMock.Object); controller.ModelState.AddModelError("Id", "InvalidId"); var id = 1; // Act var result = controller.GetRecord(id).GetAwaiter().GetResult(); // Assert Assert.IsType <BadRequestObjectResult>(result); }