public void IsFindingCorrectInfoAboutAllAuthors()
        {
            List <Author> authors = authorServices.GetAllAuthors();

            List <AuthorView> authorsViews = authorServices.GetAuthorList(authors);
            List <AuthorView> expected     = new List <AuthorView>
            {
                new AuthorView
                {
                    Id         = 1,
                    FullName   = "Author One First",
                    BooksCount = 1,
                    Country    = "Bulgaria"
                },
                new AuthorView
                {
                    Id         = 2,
                    FullName   = "Authors two second",
                    BooksCount = 3,
                    Country    = null
                }
            };

            Assert.AreEqual(expected.Count, authorsViews.Count);
        }
        public void IsGettingAllAuthorsFromDatabase()
        {
            List <Author> actual   = authorServices.GetAllAuthors();
            List <Author> expected = db.Authors.ToList();

            Assert.AreEqual(actual, expected);
        }
Example #3
0
        public void Return_Proper_Collection_Type_When_Called()
        {
            // Assert
            IAuthorServices sut = new AuthorServices(repository);

            // Act & Assert
            Assert.IsInstanceOf <IQueryable <Author> >(sut.GetAllAuthors());
        }
        public IActionResult GetAllAuthors()
        {
            var allAuthors = _authorService.GetAllAuthors();

            if (allAuthors == null)
            {
                return(NotFound());
            }
            return(Ok(allAuthors));
        }
        public void ReturnInstanceOfIQueryable_IfCalled()
        {
            // Arrange
            var            dbSetMock      = new Mock <ILibrarySystemEfWrapper <Author> >();
            AuthorServices authorServices = new AuthorServices(dbSetMock.Object);

            // Act
            IEnumerable <Author> expectedResult = new List <Author>()
            {
                new Author(), new Author(), new Author()
            };

            dbSetMock.Setup(r => r.All()).Returns(() => expectedResult.AsQueryable());

            // Assert
            Assert.IsInstanceOf <IQueryable <Author> >(authorServices.GetAllAuthors());
        }
        public void IsGettingAllAuthorsFromDatabase()
        {
            Author author = new Author
            {
                Id        = 3,
                FirstName = "FirstName3",
                LastName  = "LastName3"
            };

            authorServices.AddAuthor(author);

            bool result = authorServices
                          .GetAllAuthors()
                          .Exists(a => a.Id == author.Id);

            Assert.IsTrue(result);
        }