public async Task ThrowsError_ReturnInternalServerError() { // Assert _mockRepo.Setup(repo => repo.FindByIdAsync(It.IsAny <int>())) .Throws(new AccessViolationException()); // Act var result = await _sut.Edit(1); // Assert var redirectToPageResult = Assert.IsType <RedirectToPageResult>(result); Assert.Equal("/InternalServerError", redirectToPageResult.PageName); }
public async Task ValidId_ReturnViewWithModel() { // Arrange _mockRepo.Setup(repo => repo.FindByIdAsync(It.IsAny <int>())) .ReturnsAsync(_savedNpc); // Act var result = await _sut.Edit(1); // Assert _mockRepo.Verify(repo => repo.FindByIdAsync(It.IsAny <int>()), Times.Once); _mockRepo.Verify(repo => repo.UpdateAsync(It.IsAny <Npc>()), Times.Never); var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsType <NpcDetailsVM>(viewResult.Model); Assert.Equal("Edit", viewResult.ViewName); Assert.Equal(_savedNpc.NpcName, model.NpcName); }