public void BookDataService_CalculateTotalCost_Verify()
        {
            Mock <DbBookStoreContext> mockdb = new Mock <DbBookStoreContext>();

            var usersMockBook = UnitTestDBset.CreateDbSetMock(UnitTestDBset.BookList());

            mockdb.Setup(x => x.Book).Returns(usersMockBook.Object);

            var usersMockCategory = UnitTestDBset.CreateDbSetMock(UnitTestDBset.CategoryList());

            mockdb.Setup(x => x.Category).Returns(usersMockCategory.Object);

            var usersMockPromo = UnitTestDBset.CreateDbSetMock(UnitTestDBset.PromoList());

            mockdb.Setup(x => x.Promo).Returns(usersMockPromo.Object);

            //==========================================================
            IBook testbook    = UnitTestDBset.BookList()[3];
            var   bookservice = new BookDataService(mockdb.Object);
            var   resultcost  = bookservice.CalculateTotalCost().Result;

            IOrderCost testordercost = new OrderCost
            {
                Subtotal  = 57.74,
                Totaltax  = 5.77,
                TotalCost = 63.51
            };

            Assert.AreEqual(testordercost.Subtotal, resultcost.Subtotal);
            Assert.AreEqual(testordercost.Totaltax, resultcost.Totaltax);
            Assert.AreEqual(testordercost.TotalCost, resultcost.TotalCost);
        }
Exemplo n.º 2
0
        public void BookPromo_GetBookOriginalPrice_NotNull()
        {
            Mock <DbBookStoreContext> mockdb = new Mock <DbBookStoreContext>();

            var usersMockBook = UnitTestDBset.CreateDbSetMock(UnitTestDBset.BookList());

            mockdb.Setup(x => x.Book).Returns(usersMockBook.Object);

            var usersMockCategory = UnitTestDBset.CreateDbSetMock(UnitTestDBset.CategoryList());

            mockdb.Setup(x => x.Category).Returns(usersMockCategory.Object);

            var usersMockPromo = UnitTestDBset.CreateDbSetMock(UnitTestDBset.PromoList());

            mockdb.Setup(x => x.Promo).Returns(usersMockPromo.Object);

            //===============================================
            IBook testbook   = UnitTestDBset.BookList()[0];
            var   bookpromo  = new BookPromo(mockdb.Object);
            var   resultbook = bookpromo.GetBookOriginalPrice(testbook).Result;

            Assert.AreEqual(testbook.Cost, resultbook.Cost);
            Assert.AreEqual(testbook.Name, resultbook.Name);
            Assert.AreEqual(testbook.CategoryID, resultbook.CategoryID);
        }
Exemplo n.º 3
0
        public void BookCategory_GetBookCategory_NotNull()
        {
            Mock <DbBookStoreContext> mockdb = new Mock <DbBookStoreContext>();

            var usersMockBook = UnitTestDBset.CreateDbSetMock(UnitTestDBset.BookList());

            mockdb.Setup(x => x.Book).Returns(usersMockBook.Object);

            var usersMockCategory = UnitTestDBset.CreateDbSetMock(UnitTestDBset.CategoryList());

            mockdb.Setup(x => x.Category).Returns(usersMockCategory.Object);

            var usersMockPromo = UnitTestDBset.CreateDbSetMock(UnitTestDBset.PromoList());

            mockdb.Setup(x => x.Promo).Returns(usersMockPromo.Object);

            //===============================================
            var       Category     = new BookCategory(mockdb.Object);
            IBook     testbook     = UnitTestDBset.BookList()[1];
            ICategory testcategory = UnitTestDBset.CategoryList().FirstOrDefault(x => x.ID.Equals(testbook.CategoryID));

            var bookcategory = Category.GetBookCategory(testbook).Result;

            Assert.AreEqual(testbook.CategoryID, bookcategory.ID);
            Assert.AreEqual(testcategory?.Name, bookcategory.Name);
        }
        public void BookDataService_GetBookOrderList_NotNull()
        {
            Mock <DbBookStoreContext> mockdb = new Mock <DbBookStoreContext>();

            var usersMockBook = UnitTestDBset.CreateDbSetMock(UnitTestDBset.BookList());

            mockdb.Setup(x => x.Book).Returns(usersMockBook.Object);

            var usersMockCategory = UnitTestDBset.CreateDbSetMock(UnitTestDBset.CategoryList());

            mockdb.Setup(x => x.Category).Returns(usersMockCategory.Object);

            var usersMockPromo = UnitTestDBset.CreateDbSetMock(UnitTestDBset.PromoList());

            mockdb.Setup(x => x.Promo).Returns(usersMockPromo.Object);

            //==========================================================
            var bookservice = new BookDataService(mockdb.Object);
            var resultlist  = bookservice.GetBookOrderList().Result;

            Assert.AreEqual(UnitTestDBset.BookList().Count, resultlist.Count);
        }
        public void BookDataService_GetBookOnSale_With_Discount()
        {
            Mock <DbBookStoreContext> mockdb = new Mock <DbBookStoreContext>();

            var usersMockBook = UnitTestDBset.CreateDbSetMock(UnitTestDBset.BookList());

            mockdb.Setup(x => x.Book).Returns(usersMockBook.Object);

            var usersMockCategory = UnitTestDBset.CreateDbSetMock(UnitTestDBset.CategoryList());

            mockdb.Setup(x => x.Category).Returns(usersMockCategory.Object);

            var usersMockPromo = UnitTestDBset.CreateDbSetMock(UnitTestDBset.PromoList());

            mockdb.Setup(x => x.Promo).Returns(usersMockPromo.Object);

            //==========================================================
            IBook testbook    = UnitTestDBset.BookList()[3];
            var   bookservice = new BookDataService(mockdb.Object);
            var   resultlist  = bookservice.GetBookOnSale(testbook).Result;

            Assert.IsNotNull(resultlist.DiscountedPrice());
        }
Exemplo n.º 6
0
        public void BookPromo_GetBookPromo_EmptyOrNull()
        {
            Mock <DbBookStoreContext> mockdb = new Mock <DbBookStoreContext>();

            var usersMockBook = UnitTestDBset.CreateDbSetMock(UnitTestDBset.BookList());

            mockdb.Setup(x => x.Book).Returns(usersMockBook.Object);

            var usersMockCategory = UnitTestDBset.CreateDbSetMock(UnitTestDBset.CategoryList());

            mockdb.Setup(x => x.Category).Returns(usersMockCategory.Object);

            var usersMockPromo = UnitTestDBset.CreateDbSetMock(UnitTestDBset.PromoList());

            mockdb.Setup(x => x.Promo).Returns(usersMockPromo.Object);

            //===============================================
            IBook testbook    = UnitTestDBset.BookList()[1];
            var   bookpromo   = new BookPromo(mockdb.Object);
            var   resultpromo = bookpromo.GetBookPromo(testbook).Result;

            Assert.IsNull(resultpromo);
        }