示例#1
0
        public async Task AllShouldReturnAllPublishers()
        {
            var optionsBuilder = new DbContextOptionsBuilder <BookTubeContext>()
                                 .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var dbContext  = new BookTubeContext(optionsBuilder.Options);
            var service    = new PublisherService(dbContext);
            var publishers = new List <Publisher>
            {
                new Publisher {
                    Name = "Siela", Contacts = "Sofia, Bulgaria"
                },
                new Publisher {
                    Name = "East-West", Contacts = "Some Contacs"
                },
                new Publisher {
                    Name = "Anubis", Contacts = "Ruse, Bulgaria"
                }
            };

            foreach (var publisher in publishers)
            {
                await dbContext.Publishers.AddAsync(publisher);
            }
            await dbContext.SaveChangesAsync();

            var sortedPublishers = publishers.OrderBy(x => x.Name).ToList();
            var actual           = service.All();

            Assert.Equal(sortedPublishers, actual);
        }
示例#2
0
        public async Task AllShouldReturnAllAuthors()
        {
            var optionsBuilder = new DbContextOptionsBuilder <BookTubeContext>()
                                 .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var dbContext = new BookTubeContext(optionsBuilder.Options);
            var service   = new AuthorsService(dbContext);

            var authors = new List <Author>
            {
                new Author {
                    Id = 1, Name = "Ivan Vazov", Bio = "Born in Sopot, Bulgaria"
                },
                new Author {
                    Id = 2, Name = "Aleko Konstantinov", Bio = "Born in Svishtov, Bulgaria"
                },
                new Author {
                    Id = 3, Name = "Elin Pelin", Bio = "Born in Bailovo, Bulgaria"
                }
            };

            foreach (var author in authors)
            {
                await dbContext.Authors.AddAsync(author);
            }
            await dbContext.SaveChangesAsync();

            var sortedPublishers = authors.OrderBy(x => x.Name).ToList();
            var actual           = service.All();

            Assert.Equal(sortedPublishers, actual);
        }
示例#3
0
        public async Task GetAuthorByIdShouldreturnAuthorWithSelectedId()
        {
            var optionsBuilder = new DbContextOptionsBuilder <BookTubeContext>()
                                 .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var dbContext = new BookTubeContext(optionsBuilder.Options);
            var service   = new AuthorsService(dbContext);

            var authors = new List <Author>
            {
                new Author {
                    Id = 1, Name = "Ivan Vazov", Bio = "Born in Sopot, Bulgaria"
                },
                new Author {
                    Id = 2, Name = "Aleko Konstantinov", Bio = "Born in Svishtov, Bulgaria"
                },
                new Author {
                    Id = 3, Name = "Elin Pelin", Bio = "Born in Bailovo, Bulgaria"
                }
            };

            foreach (var author in authors)
            {
                await dbContext.Authors.AddAsync(author);
            }
            await dbContext.SaveChangesAsync();

            var expectedAuthor = authors.First(x => x.Id == 2);
            var actual         = service.GetAuthorById(2);

            Assert.Equal(expectedAuthor, actual);
        }
        public async Task GetBookByCategoryShouldreturnBooksWithSelectedCategory()
        {
            var optionsBuilder = new DbContextOptionsBuilder <BookTubeContext>()
                                 .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var dbContext = new BookTubeContext(optionsBuilder.Options);
            var service   = new BooksService(dbContext);

            var books = new List <Book>
            {
                new Book {
                    Id = 1, Title = "It", AuthorId = 1, PublisherId = 1, CategoryId = 1, PublicationYear = 1986, Isbn = "1111", Description = "Some description"
                },
                new Book {
                    Id = 2, Title = "Crime and punishment", AuthorId = 2, PublisherId = 2, CategoryId = 2, PublicationYear = 1866, Isbn = "2222", Description = "Some description"
                },
                new Book {
                    Id = 3, Title = "Bay Ganyo", AuthorId = 3, PublisherId = 3, CategoryId = 2, PublicationYear = 1896, Isbn = "3333", Description = "Some description"
                }
            };

            foreach (var book in books)
            {
                await dbContext.Books.AddAsync(book);
            }
            await dbContext.SaveChangesAsync();

            var expectedBooks = books.Where(x => x.CategoryId == 2).ToList();
            var actual        = service.GetBooksByCategory(2);

            Assert.Equal(expectedBooks, actual);
        }
        public async Task AllShouldReturnAllcategories()
        {
            var categories = new List <Category>
            {
                new Category {
                    Name = "Art"
                },
                new Category {
                    Name = "History"
                },
                new Category {
                    Name = "Philosophy"
                }
            };

            var optionsBuilder = new DbContextOptionsBuilder <BookTubeContext>()
                                 .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var dbContext = new BookTubeContext(optionsBuilder.Options);
            var service   = new CategoriesService(dbContext);

            foreach (var category in categories)
            {
                await dbContext.Categories.AddAsync(category);
            }
            await dbContext.SaveChangesAsync();

            var actual = service.All();

            Assert.Equal(categories, actual);
        }
示例#6
0
        public async Task AddShouldAddPublisher()
        {
            var optionsBuilder = new DbContextOptionsBuilder <BookTubeContext>()
                                 .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var dbContext = new BookTubeContext(optionsBuilder.Options);
            var service   = new PublisherService(dbContext);

            var publisher = new Publisher
            {
                Id       = 1,
                Name     = "Siela",
                Contacts = "Sofia, Bulgaria"
            };

            await service.AddPublisher(publisher.Name, publisher.Contacts);

            var publisherFromDb = dbContext.Publishers.Select(x => x.Name).First();

            Assert.Equal(publisherFromDb, publisher.Name);
        }
示例#7
0
        public async Task AddAuthorShouldAddAuthor()
        {
            var optionsBuilder = new DbContextOptionsBuilder <BookTubeContext>()
                                 .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var dbContext = new BookTubeContext(optionsBuilder.Options);
            var service   = new AuthorsService(dbContext);

            var author = new Author
            {
                Id   = 1,
                Name = "Ivan Vazov",
                Bio  = "Born in Sopot, Bulgaria"
            };

            await service.AddAuthor(author.Name, author.Bio);

            var authorFromDb = dbContext.Authors.Select(x => x.Name).First();

            Assert.Equal(authorFromDb, author.Name);
        }
 public BooksService(BookTubeContext db)
 {
     this.db = db;
 }
示例#9
0
 public PublisherService(BookTubeContext db)
 {
     this.db = db;
 }
 public AuthorsService(BookTubeContext db)
 {
     this.db = db;
 }
 public ReviewsService(BookTubeContext db)
 {
     this.db = db;
 }
示例#12
0
 public CategoriesService(BookTubeContext db)
 {
     this.db = db;
 }