コード例 #1
0
        public ActionResult Create(CreateBookViewModel createBookViewModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var book = new Book()
                    {
                        Title = createBookViewModel.Book.Title
                    };

                    foreach (var authorId in createBookViewModel.SelectedAuthors)
                    {
                        book.AuthorId.Add(authorId);
                    }

                    bookService.AddNewBook(book);

                    return(RedirectToAction(nameof(Index)));
                }
                catch
                {
                    return(View());
                }
            }

            return(View());
        }
コード例 #2
0
    public void CanCreateUser()
    {
        var Book = new BookService(context);

        Data.Database.Entities.Book book = Book.AddNewBook("test");
        context.SaveChanges();
        book.Id.Should().NotBe(0);
        book.Name.Should().Be("test");
    }
コード例 #3
0
 public override void AddNewValidEntityShouldBeSuccessful()
 {
     Assert.AreEqual(true, service.AddNewBook(book), "Expected validation to pass");
 }