コード例 #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);
        }
コード例 #2
0
        public void MainUnitTestTest()
        {
            BookStoreController b = new BookStoreController();
            var q = b.MainUnitTest(5);

            Assert.AreEqual(8, q);
        }
コード例 #3
0
        public void MainUnitTestLessTest()
        {
            BookStoreController b = new BookStoreController();
            var q2 = b.MainUnitTest(5);

            Assert.AreNotEqual(6, q2);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        public void BookStoreController_IsInstanceOf_BookStoreController_ReceivingBookStoreServiceOnCreation_Test()
        {
            // Arrange
            var controller = new BookStoreController(_bookStoreService.Object);

            // Act | Assert
            Assert.IsInstanceOf <BookStoreController>(controller);
        }
コード例 #6
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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";
        }
コード例 #15
0
        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);
        }
コード例 #17
0
        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);
        }
コード例 #18
0
        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} ");
        }
コード例 #20
0
        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);
        }