Esempio n. 1
0
        public void Library_RemoveAutor_Correct()
        {
            // Arrage
            List <Author> authors = new List <Author>()
            {
                new Author()
                {
                    Id = 0, Name = "Name0", Surname = "Surname0"
                },
                new Author()
                {
                    Id = 1, Name = "Name1", Surname = "Surname1"
                },
                new Author()
                {
                    Id = 2, Name = "Name2", Surname = "Surname2"
                },
            };

            List <BookAuthor> bookAuthors = new List <BookAuthor>()
            {
                new BookAuthor()
                {
                    BookIndex = 0, AuthorIndex = 0
                },
                new BookAuthor()
                {
                    BookIndex = 0, AuthorIndex = 1
                },
                new BookAuthor()
                {
                    BookIndex = 1, AuthorIndex = 2
                },
                new BookAuthor()
                {
                    BookIndex = 1, AuthorIndex = 1
                },
            };
            Mock <IDataProvider> data = new Mock <IDataProvider>();

            Mock <IDataProvider> data = new Mock <IDataProvider>();

            data.Setup(p => p.GetAuthors()).Returns(authors);
            data.Setup(p => p.GetBooksAuthors()).Returns(bookAuthors);

            ILibrary library = new LibraryCollection(data.Object);

            // Act
            bookAuthors.RemoveAll(item => item.AuthorIndex == 0);
            authors.RemoveAt(0);
            library.RemoveAuthor(0);

            // Assert
            Assert.Equal(authors, library.GetAuthors());
            Assert.Equal(bookAuthors, library.GetBookAuthors());
        }
Esempio n. 2
0
        public void Library_AddAuthor_Correct()
        {
            // Arrage
            List <Author> authors = new List <Author>()
            {
                new Author()
                {
                    Id = 1, Name = "Name0", Surname = "Surname0"
                },
                new Author()
                {
                    Id = 2, Name = "Name1", Surname = "Surname1"
                },
                new Author()
                {
                    Id = 3, Name = "Name2", Surname = "Surname2"
                },
            };

            Mock <IDataProvider> data = new Mock <IDataProvider>();

            data.Setup(p => p.GetAuthors()).Returns(authors);

            ILibrary library   = new LibraryCollection(data.Object);
            Author   newAuthor = new Author()
            {
                Id = 20, Name = "Name10", Surname = "Surname10"
            };

            // Act
            authors.Add(newAuthor);
            library.AddAuthor(newAuthor);

            // Assert
            Assert.Equal(authors, library.GetAuthors());
        }