示例#1
0
        public void TestGetFavBook()
        {
            Mock <ModelOperation> moc = new Mock <ModelOperation>();

            List <BookStore> bookModel = new List <BookStore>()
            {
                new BookStore
                {
                    BookId           = 1,
                    BookName         = "LifeStory",
                    AuthorFirsttName = "Arvindh",
                    AuthorlastName   = "Gosam",
                    Gender           = "M",
                    PYear            = 2013,
                    BookPrice        = 353,
                    Flag             = 1
                }
            };

            moc.Setup(m => m.GetFavList()).Returns(new List <BookStoreModel>());
            var controller         = new BookStoreController(moc.Object);
            IHttpActionResult http = controller.GetFavList();
            var actual             = http as OkNegotiatedContentResult <List <BookStoreModel> >;

            CollectionAssert.Equals(actual, bookModel);
        }
        public void MainUnitTestTest()
        {
            BookStoreController b = new BookStoreController();
            var q = b.MainUnitTest(5);

            Assert.AreEqual(8, q);
        }
        public void MainUnitTestLessTest()
        {
            BookStoreController b = new BookStoreController();
            var q2 = b.MainUnitTest(5);

            Assert.AreNotEqual(6, q2);
        }
        public void GivenController_ConutBook_Method_ShouldReturn_Count()
        {
            var service    = new Mock <IBookManager>();
            var controller = new BookStoreController(service.Object);
            var count      = controller.CountBook();

            Assert.IsNotNull(count);
        }
        public void BookStoreController_IsInstanceOf_BookStoreController_ReceivingBookStoreServiceOnCreation_Test()
        {
            // Arrange
            var controller = new BookStoreController(_bookStoreService.Object);

            // Act | Assert
            Assert.IsInstanceOf <BookStoreController>(controller);
        }
        public void GivenController_GetAllBooks_Method_ShouldReturn_Data()
        {
            var service    = new Mock <IBookManager>();
            var controller = new BookStoreController(service.Object);
            var data       = controller.GetALLBooks();

            Assert.IsNotNull(data);
        }
示例#7
0
        public async Task BookStoreController_Get_Should_Return_ActionResult()
        {
            //Arrange
            var controller = new BookStoreController();

            //Act
            var result = await controller.Get();

            //Assert
            Assert.IsType <JsonResult>(result);
        }
        public void WhenCallGetPriceThatThrowsNotEnoughInventoryException_ReturnsBadRequestErrorMessageResult()
        {
            string[] names = new string[] { "name of a book" };
            _bookStoreService.Setup(m => m.BooksPrice(names)).Throws(new NotEnoughInventoryException());
            BookStoreController controller = new BookStoreController(_bookStoreService.Object);

            var result = controller.GetPrice(names);

            Assert.IsNotNull(result);
            Assert.IsInstanceOf(typeof(BadRequestErrorMessageResult), result);
        }
        public void WhenCallGetPrice_ReturnsOk()
        {
            string[] names = new string[] { "name of a book" };
            _bookStoreService.Setup(m => m.BooksPrice(names)).Returns(10);
            BookStoreController controller = new BookStoreController(_bookStoreService.Object);

            var result = controller.GetPrice(names);

            Assert.IsNotNull(result);
            Assert.IsInstanceOf(typeof(OkNegotiatedContentResult <double>), result);
        }
示例#10
0
        public void TestDelete(int id)
        {
            Mock <ModelOperation> moc = new Mock <ModelOperation>();

            moc.Setup(m => m.Delete(id)).Returns(1);
            var controller         = new BookStoreController(moc.Object);
            IHttpActionResult http = controller.Delete(id);
            var actual             = http as OkNegotiatedContentResult <string>;

            Assert.AreEqual("Deleted Success", actual);
        }
        public void WhenCallGetQuantityWithoutName_ReturnsBadRequestErrorMessageResult()
        {
            string name = string.Empty;

            _bookStoreService.Setup(m => m.BookQuantity(name)).Returns(1);
            BookStoreController controller = new BookStoreController(_bookStoreService.Object);

            var result = controller.GetQuantity(name);

            Assert.IsNotNull(result);
            Assert.IsInstanceOf(typeof(BadRequestErrorMessageResult), result);
        }
        public void WhenCallGetQuantityWithName_ReturnsOk()
        {
            string name = "name of a book";

            _bookStoreService.Setup(m => m.BookQuantity(name)).Returns(1);
            BookStoreController controller = new BookStoreController(_bookStoreService.Object);

            var result = controller.GetQuantity(name);

            Assert.IsNotNull(result);
            Assert.IsInstanceOf(typeof(OkNegotiatedContentResult <int>), result);
        }
示例#13
0
        public void GetAllBooks()
        {
            // Arrange
            BookStoreController controller = new BookStoreController(_bookStoreService);

            var testTransaction = new Transaction()
            {
                BookId = 1, CustomerId = 2
            };

            var details = controller.GetAllBooks();
        }
示例#14
0
        public void GivenController_Api_Should_Return_Data()
        {
            var service    = new Mock <IBookManager>();
            var controller = new BookStoreController(service.Object);

            book.BookID     = 1;
            book.AuthorName = "Ravindhar";
            book.BookTittle = "My LifeStyle";
            book.BookCount  = 1;
            book.Summary    = "this book is written to expose my biography";
            book.Price      = 400;
            book.BookImage  = "img.jpg";
        }
        public void WhenCallInsertWithCorrectJsonSchema_ReturnsOkResult()
        {
            _bookStoreService.Setup(m => m.ImportStock(CATALOGASJSON)).Returns("import successfully");

            BookStoreController controller = new BookStoreController(_bookStoreService.Object);
            BookStoreModel      model      = new BookStoreModel();

            model.CatalogAsJson = CATALOGASJSON;

            var result = controller.Import(model);

            Assert.IsNotNull(result);
            Assert.IsInstanceOf(typeof(OkNegotiatedContentResult <string>), result);
        }
示例#16
0
        public void TestAddBook()
        {
            Mock <ModelOperation> mock           = new Mock <ModelOperation>();
            BookStoreModel        bookStoreModel = new BookStoreModel();

            //BookStore store = new BookStore();

            mock.Setup(m => m.AddBooks(bookStoreModel)).Returns(1);
            var controller         = new BookStoreController(mock.Object);
            IHttpActionResult http = controller.Post(bookStoreModel);
            var actual             = http as OkNegotiatedContentResult <string>;

            Assert.AreEqual("Success inserted book", actual.Content);
        }
        public void WhenCallImportWithEmptyCatalogAsJson_ReturnsBadRequestErrorMessageResult()
        {
            _bookStoreService.Setup(m => m.ImportStock(CATALOGASJSON)).Returns("import successfully");

            BookStoreController controller = new BookStoreController(_bookStoreService.Object);
            BookStoreModel      model      = new BookStoreModel();

            model.CatalogAsJson = string.Empty;

            var result = controller.Import(model);

            Assert.IsNotNull(result);
            Assert.IsInstanceOf(typeof(BadRequestErrorMessageResult), result);
        }
        public void GetAllAuthorsTest_AuthorListValue()
        {
            // arrange
            var    data     = GetFakeAuthor(5);
            String expected = data.First().Name;

            var service = new Mock <IBookStoreService>();

            service.Setup(x => x.GetAllAuthorsService()).Returns(data);
            var controller = new BookStoreController(service.Object);

            // act
            String actual = controller.GetAllAuthors().First().Name;

            // assert
            Assert.Equal(expected, actual);
        }
示例#19
0
        public async Task BookStoreController_Get_Should_Return_Correct_BookStore_Data()
        {
            //Arrange
            var controller = new BookStoreController();

            //Act


            var result = await controller.Get();

            var json = result.ToJson <BookStore>();

            //Assert
            Assert.True(json[0].Name == "Waterstones", $"Assert failed, received {json[0].Name} ");
            Assert.True(json[0].PostCode == "PO19 1QD", $"Assert failed, received {json[0].PostCode} ");
            Assert.True(json[0].TelephoneNumber == "01234 773030", $"Assert failed, received {json[0].TelephoneNumber} ");
        }
        public void GetAllBooksTest_BookListSize()
        {
            // arrange
            int expected = 10;
            var data     = GetFakeBook(expected);

            var service = new Mock <IBookStoreService>();

            service.Setup(x => x.GetAllBooksService()).Returns(data);
            var controller = new BookStoreController(service.Object);

            // act
            int actual = controller.GetAllBooks().Count();

            // assert
            Assert.Equal(expected, actual);
        }
示例#21
0
        public void PurchaseBook()
        {
            // Arrange
            BookStoreController controller = new BookStoreController(_bookStoreService);

            var testTransaction = new Transaction()
            {
                BookId = 1, CustomerId = 2
            };

            var details = controller.PurchaseBook(testTransaction);

            // Assert.
            Assert.IsNotNull(details);
            Assert.IsTrue(details.IsSuccess);
            Assert.IsNotNull(details.Data);
            Assert.AreNotEqual(0, details.Data.Id);
        }