Ejemplo n.º 1
0
        public ActionResult AddAuthor(string name)
        {
            AuthorsService service = new AuthorsService();
            int            id      = service.AddAuthor(name);

            return(RedirectToAction("AuthorsSelectList", new { selectedId = id }));
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
 public IActionResult AddAuthor([FromBody] AuthorVM author)
 {
     _authorsService.AddAuthor(author);
     return(Ok());
 }