示例#1
0
        public void GetBook_ShouldReturnBookWithSameID()
        {
            var context = new TestBookstoreAppContext();

            context.Books.Add(GetDemoBook());

            var controller = new BookController(context);
            var result     = controller.GetBook(3) as OkNegotiatedContentResult <Book>;

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Content.Id);
        }
示例#2
0
        public void DeleteBook_ShouldReturnOK()
        {
            var context = new TestBookstoreAppContext();
            var item    = GetDemoBook();

            context.Books.Add(item);

            var controller = new BookController(context);
            var result     = controller.DeleteBook(3) as OkNegotiatedContentResult <Book>;

            Assert.IsNotNull(result);
            Assert.AreEqual(item.Id, result.Content.Id);
        }
示例#3
0
        public void GetBooks_ShouldReturnAllBooks()
        {
            var context = new TestBookstoreAppContext();

            context.Books.Add(new Book {
                Id = 1, Name = "Metro 2033", Price = 20
            });
            context.Books.Add(new Book {
                Id = 2, Name = "Metro 2034", Price = 30
            });
            context.Books.Add(new Book {
                Id = 3, Name = "Metro 2035", Price = 40
            });

            var controller = new BookController(context);
            var result     = controller.GetBooks() as TestBookDbSet;

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Local.Count);
        }