public void Details_ReturnsBadRequest_WhenNoIdProvided()
        {
            //Arrange

            //Act
            var result = _leagueController.Details(null);

            //Assert
            Assert.NotNull(result);
            var viewModel = Assert.IsAssignableFrom <BadRequestResult>(result);
        }
        public async Task CallFindAsync_WhenCalled()
        {
            // Arrange
            Mock <ILeagueService> leagueServiceMock = new Mock <ILeagueService>();
            Mock <IPDFService>    pDFServiceMock    = new Mock <IPDFService>();
            Mock <IMemoryCache>   memoryCacheMock   = new Mock <IMemoryCache>();

            string validId = string.Empty;

            League validLeagueResult = new League();

            leagueServiceMock.Setup(mock => mock.FindAsync(validId))
            .Returns(Task.FromResult(validLeagueResult));

            LeagueController SUT = new LeagueController(
                leagueServiceMock.Object,
                pDFServiceMock.Object,
                memoryCacheMock.Object);

            // Act
            await SUT.Details(validId);

            // Assert
            leagueServiceMock.Verify(mock => mock.FindAsync(validId), Times.Once);
        }
        public async Task ReturnCorrectViewModel_WhenCalled()
        {
            // Arrange
            Mock <ILeagueService> leagueServiceMock = new Mock <ILeagueService>();
            Mock <IPDFService>    pDFServiceMock    = new Mock <IPDFService>();
            Mock <IMemoryCache>   memoryCacheMock   = new Mock <IMemoryCache>();

            string validId = string.Empty;

            League validLeagueResult = new League();

            leagueServiceMock.Setup(mock => mock.FindAsync(validId))
            .Returns(Task.FromResult(validLeagueResult));

            LeagueController SUT = new LeagueController(
                leagueServiceMock.Object,
                pDFServiceMock.Object,
                memoryCacheMock.Object);

            // Act
            var result = await SUT.Details(validId) as ViewResult;

            // Assert
            Assert.IsInstanceOfType(result.Model, typeof(LeagueDetailsViewModel));
        }
예제 #4
0
        public async Task Test_Details_Returns_League()
        {
            var result = await controller.Details(1);

            var model = ((ViewResult)result).Model as League;

            Assert.AreEqual("Championship", model.Name);
        }
        public async Task ThrowApplicationException_WhenPassedNullId()
        {
            // Arrange
            Mock <ILeagueService> leagueServiceMock = new Mock <ILeagueService>();
            Mock <IPDFService>    pDFServiceMock    = new Mock <IPDFService>();
            Mock <IMemoryCache>   memoryCacheMock   = new Mock <IMemoryCache>();

            string validId = string.Empty;

            League validLeagueResult = new League();

            leagueServiceMock.Setup(mock => mock.FindAsync(validId))
            .Returns(Task.FromResult(validLeagueResult));

            LeagueController SUT = new LeagueController(
                leagueServiceMock.Object,
                pDFServiceMock.Object,
                memoryCacheMock.Object);

            // Act & Assert
            await Assert.ThrowsExceptionAsync <ApplicationException>(() =>
                                                                     SUT.Details(null));
        }