Ejemplo n.º 1
0
        public void Add_Single_Book()
        {
            var newBook = new Book();

            var response = booksController.Post(newBook);

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.AreEqual(1, (service.Books as FakeRepository<Book>).added.Count);
            //
            // TODO: Add test logic here
            //
        }
Ejemplo n.º 2
0
        public HttpResponseMessage Post(Book book)
        {
            var response = new HttpResponseMessage();
            if (ModelState.IsValid)
            {
                book.ReleaseDate = DateTime.Now.AddMonths(-1);
                service.Books.Insert(book);
                service.Save();
                response.StatusCode = HttpStatusCode.OK;
                response.Content = new StringContent("Book added.", Encoding.UTF8, "text/plain");
            }
            else
            {
                response.StatusCode = HttpStatusCode.Conflict;
                response.Content = new StringContent("Invalid data.", Encoding.UTF8, "text/plain");
            }

            return response;
        }