public async Task ReturnCorrectViewModel_WhenCalled() { // Arrange Mock <ITeamService> teamServiceMock = new Mock <ITeamService>(); Mock <IPDFService> pDFServiceMock = new Mock <IPDFService>(); Mock <IMemoryCache> memoryCacheMock = new Mock <IMemoryCache>(); string validId = string.Empty; Team validTeamResult = new Team(); teamServiceMock.Setup(mock => mock.FindAsync(validId)) .Returns(Task.FromResult(validTeamResult)); TeamController SUT = new TeamController( teamServiceMock.Object, pDFServiceMock.Object, memoryCacheMock.Object); // Act var result = await SUT.Details(validId) as ViewResult; // Assert Assert.IsInstanceOfType(result.Model, typeof(TeamDetailsViewModel)); }
public async Task CallFindAsync_WhenCalled() { // Arrange Mock <ITeamService> teamServiceMock = new Mock <ITeamService>(); Mock <IPDFService> pDFServiceMock = new Mock <IPDFService>(); Mock <IMemoryCache> memoryCacheMock = new Mock <IMemoryCache>(); string validId = string.Empty; Team validTeamResult = new Team(); teamServiceMock.Setup(mock => mock.FindAsync(validId)) .Returns(Task.FromResult(validTeamResult)); TeamController SUT = new TeamController( teamServiceMock.Object, pDFServiceMock.Object, memoryCacheMock.Object); // Act await SUT.Details(validId); // Assert teamServiceMock.Verify(mock => mock.FindAsync(validId), Times.Once); }
public async Task Test_Details_Returns_Team() { var result = await controller.Details(1); var model = ((ViewResult)result).Model as Team; Assert.AreEqual("Newcastle United", model.Name); }
public async Task ThrowApplicationException_WhenPassedNullId() { // Arrange Mock <ITeamService> teamServiceMock = new Mock <ITeamService>(); Mock <IPDFService> pDFServiceMock = new Mock <IPDFService>(); Mock <IMemoryCache> memoryCacheMock = new Mock <IMemoryCache>(); string invalidId = null; Team validTeamResult = new Team(); teamServiceMock.Setup(mock => mock.FindAsync(invalidId)) .Returns(Task.FromResult(validTeamResult)); TeamController SUT = new TeamController( teamServiceMock.Object, pDFServiceMock.Object, memoryCacheMock.Object); // Act & Assert await Assert.ThrowsExceptionAsync <ApplicationException>(() => SUT.Details(invalidId)); }