public async Task ReturnCorrectViewModel_WhenCalled()
        {
            // Arrange
            Mock <IMasteryService> masteryServiceMock = new Mock <IMasteryService>();
            Mock <IPDFService>     pDFServiceMock     = new Mock <IPDFService>();
            IMemoryCache           memoryCacheMock    = new MemoryCache(new MemoryCacheOptions());

            string validSortOrder  = string.Empty;
            string validFilter     = string.Empty;
            int    validPageNumber = 1;
            int    validPageSize   = 10;

            IPagedList <Mastery> masterys = new PagedList <Mastery>(new List <Mastery>().AsQueryable(), validPageNumber, validPageSize);

            masteryServiceMock.Setup(mock => mock.FilterMasteriesAsync(validSortOrder, validFilter, validPageNumber, validPageSize))
            .Returns(Task.FromResult(masterys));

            MasteryController SUT = new MasteryController(
                masteryServiceMock.Object,
                pDFServiceMock.Object,
                memoryCacheMock);

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

            // Assert
            Assert.IsInstanceOfType(result.Model, typeof(MasteryIndexViewModel));
        }
Exemplo n.º 2
0
        public async Task CallFilterMasteriesAsync_WhenCalled()
        {
            // Arrange
            Mock <IMasteryService> masteryServiceMock = new Mock <IMasteryService>();
            Mock <IPDFService>     pDFServiceMock     = new Mock <IPDFService>();
            Mock <IMemoryCache>    memoryCacheMock    = new Mock <IMemoryCache>();

            string validSortOrder  = string.Empty;
            string validFilter     = string.Empty;
            int    validPageNumber = 1;
            int    validPageSize   = 10;

            IPagedList <Mastery> masterys = new PagedList <Mastery>(new List <Mastery>().AsQueryable(), validPageNumber, validPageSize);

            masteryServiceMock.Setup(mock => mock.FilterMasteriesAsync(validSortOrder, validFilter, validPageNumber, validPageSize))
            .Returns(Task.FromResult(masterys));

            MasteryController SUT = new MasteryController(
                masteryServiceMock.Object,
                pDFServiceMock.Object,
                memoryCacheMock.Object);

            // Act
            await SUT.Filter(validSortOrder, validFilter, validPageSize, validPageNumber);

            // Assert
            masteryServiceMock
            .Verify(mock => mock.FilterMasteriesAsync(validSortOrder, validFilter, validPageNumber, validPageSize),
                    Times.Once);
        }