Exemple #1
0
        public void ValidateTitle()
        {
            var book = CreateBook();

            book.Title = "  ";

            try
            {
                bookBLL.Add(book);
                Assert.Fail("Title check not working for books!");
            }
            catch (BusinessLogicException ex) { }

            book.Title    = "Book Title Test";
            book.Quantity = -5;

            try
            {
                bookBLL.Add(book);
                Assert.Fail("Quantity check not working for books!");
            }
            catch (BusinessLogicException ex) { }

            book.Quantity = 5;
            book.Price    = -5;

            try
            {
                bookBLL.Add(book);
                Assert.Fail("Price check not working for books!");
            }
            catch (BusinessLogicException ex) { }

            book.Price     = 10;
            book.Publisher = null;

            try
            {
                bookBLL.Add(book);
                Assert.Fail("Publisher check not working for books!");
            }
            catch (BusinessLogicException ex) { }

            book.Publisher = publisher;
            book.Authors   = new List <Author>();

            try
            {
                bookBLL.Add(book);
                Assert.Fail("Author check not working for books!");
            }
            catch (BusinessLogicException ex) { }
        }
        public IHttpActionResult Add(BookVm bookVm)
        {
            try
            {
                var book = MapToBook(bookVm);
                _bookBLL.Add(book);

                bookVm.Id = book.Id;

                var bookDto = MapToBookDto(book);
                return(Ok(bookDto));
            }
            catch (BusinessLogicException ex)
            {
                return(Content(HttpStatusCode.BadRequest, new ErrorResult(ex.Message)));
            }
            catch (Exception ex)
            {
                return(Content(HttpStatusCode.InternalServerError, new ErrorResult(Resources.Messages.Status500)));
            }
        }