Exemplo n.º 1
0
        public void IndexView_NotNull()
        {
            var mock = new Mock <IAuthorLogic>();

            mock.Setup(a => a.GetAll()).Returns(new List <Author>());
            AuthorController controller = new AuthorController(mock.Object);
            ViewResult       result     = controller.Index() as ViewResult;

            Assert.IsNotNull(result.Model);
        }
Exemplo n.º 2
0
        public void Task_Get_All_Author_Return_OkResult()
        {
            //Arrange
            var controller = new AuthorController(context);

            //Act
            var data = controller.Index();

            //Assert
            Assert.IsType <ViewResult>(data);
        }
        public void CanSendPaginationViewModel()
        {
            var mock = CreateAndSetupMock(10);
            AuthorController target = new AuthorController(mock.Object)
            {
                PageSize = 3
            };
            PagingInfo result = GetViewModel <ListViewModel <Author> >(target.Index(2))?.PagingInfo;

            Assert.Equal(2, result.CurrentPage);
            Assert.Equal(3, result.ItemsPerPage);
            Assert.Equal(10, result.TotalItems);
            Assert.Equal(4, result.TotalPages);
        }
        public void CanPaginate()
        {
            var mock = CreateAndSetupMock(9);
            AuthorController target = new AuthorController(mock.Object)
            {
                PageSize = 5
            };

            Author[] result = GetViewModel <ListViewModel <Author> >(target.Index(2))?.Entities.ToArray();

            Assert.True(result.Length == 4);
            Assert.Equal("Фамилия6", result[0].Surname);
            Assert.Equal("Имя7", result[1].Name);
            Assert.Equal("Отчество8", result[2].Patronymic);
            Assert.Equal("Имя9", result[3].Name);
        }
        public void Index_ReturnsCorrectViewWithAllAuthors()
        {
            //Arrange
            IRepository mockRepo = Substitute.For <IRepository>();

            mockRepo.Authors.Returns(_authors);

            //Act
            AuthorController target = new AuthorController(mockRepo);
            ActionResult     result = target.Index();

            //Assert
            Assert.IsInstanceOf <ViewResult>(result);
            IEnumerable <Author> model = (result as ViewResult).Model as IEnumerable <Author>;

            Assert.AreEqual(_authors.Count(), model.Count());
            Assert.AreEqual("L1", model.First().LastName);
        }
        public void IndexContainsAllAuthors(int size)
        {
            var mock = CreateAndSetupMock(size);
            AuthorController target = new AuthorController(mock.Object)
            {
                PageSize = size + 1
            };

            Author[] result = GetViewModel <ListViewModel <Author> >(target.Index(1))?.Entities.ToArray();

            Assert.Equal(size, result.Length);
            for (int i = 0; i < size; ++i)
            {
                Assert.Equal(i + 1, result[i].Id);
                Assert.Equal($"Имя{i+1}", result[i].Name);
                Assert.Equal($"Фамилия{i+1}", result[i].Surname);
                Assert.Equal($"Отчество{i+1}", result[i].Patronymic);
                Assert.Equal($"Описание{i+1}", result[i].Description);
            }
        }
Exemplo n.º 7
0
        // Test AuthorController getting a list of authors
        public void DoesGetAuthors()
        {
            // Arrange
            var repository = new FakeAuthorRepository();
            var controller = new AuthorController(repository);

            // Act
            var authors = (List <Author>)controller.Index().ViewData.Model;

            // Assert
            if (authors != null)
            {
                Assert.Equal(repository.GetAllAuthors()[0].Name,
                             authors[0].Name);
                Assert.Equal(repository.GetAllAuthors()[0].Birthday,
                             authors[0].Birthday);
                Assert.Equal(repository.GetAllAuthors()[1].Name,
                             authors[1].Name);
                Assert.Equal(repository.GetAllAuthors()[1].Birthday,
                             authors[1].Birthday);
            }
        }