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); }
public void BookPromo_GetBookPromo_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 resultpromo = bookpromo.GetBookPromo(testbook).Result; Assert.AreEqual(testbook.PromoID, resultpromo.ID); Assert.AreNotEqual(0, resultpromo.Discount); }