コード例 #1
0
        public async Task Index_ReturnViewResult_With_Documents()
        {
            // Arrange
            ApplicationUser user = new ApplicationUser
            {
                Id = "ids"
            };
            Mock <IUserRepository> mockUserRepo = new Mock <IUserRepository>();
            HttpContext            temp         = null;

            mockUserRepo.Setup(repo => repo.getUserFromHttpContextAsync(temp))
            .ReturnsAsync(user);

            Mock <IDocumentRepository> mockDocRepo = new Mock <IDocumentRepository>();

            mockDocRepo.Setup(repo => repo.GetDocumentsOfCurrentUser(user.Id))
            .Returns(GetDocumentsOfCurrentUser());

            DocumentsController controller = new DocumentsController(
                mockUserRepo.Object, mockDocRepo.Object);

            // Act
            IActionResult result = await controller.Index();

            // Assert
            ViewResult             viewResult = Assert.IsType <ViewResult>(result);
            IEnumerable <Document> model      = Assert.IsAssignableFrom <IEnumerable <Document> >(
                viewResult.ViewData.Model);

            Assert.Equal(10, model.Count());
        }
コード例 #2
0
        public void IndexViewModelNotNull()
        {
            var mock = new Mock <IDocRepository>();

            mock.Setup(a => a.GetDocumentsList()).Returns(new List <Document>());
            DocumentsController controller = new DocumentsController(mock.Object);

            ViewResult result = controller.Index() as ViewResult;

            Assert.IsNotNull(result.Model);
        }
コード例 #3
0
        public async Task TestingGetDocumentsFromStudentWithNoDocuments()
        {
            //InitializeDatabaseWithDataTest();
            DocumentsController controller = new DocumentsController(_context);

            string studentIndex = _context.Students.Where(m => m.UserFullname == "Teste User 2").First().Id;
            int    appId        = _context.Applications.Where(a => a.StudentId.Equals(studentIndex)).FirstOrDefault().ApplicationId;
            // Act
            var result = await controller.Index(appId);

            // Assert
            var viewResult = Assert.IsType <ViewResult>(result);
            var model      = Assert.IsAssignableFrom <IEnumerable <Document> >(
                viewResult.ViewData.Model);

            Assert.Empty(model);
        }