public void Add_New_Content_In_Cart() { var notifyDto = new NotificationDto(); // Setup Mock Product mockNotify.Setup(item => item.AddToCartNotify(It.IsAny <AddToCartNotifyDto>())) .Returns(() => notifyDto); // Create object Product var product = new Product() { Id = 1 }; // Setup Mock Product mockProduct.Setup(item => item.Get(It.IsAny <long>())) .Returns(() => product); // Create object ContentCart var objContentCart = new ContentCart() { Id = 5 }; var actual1 = objContentCart.Id; // Create List for search by content.Id List <ContentCart> contentCartList = new List <ContentCart>(); // Setup mock object mock.Setup(item => item.Find(It.IsAny <Expression <Func <ContentCart, bool> > >())) .Returns(() => contentCartList); mock.Setup(repo => repo.Add(It.IsAny <ContentCart>())) .Returns(() => objContentCart).Callback(() => objContentCart.Id++); // Create CartService object with mock.Object and mockProduct.Object var service = new CartService(mock.Object, mockProduct.Object, mockNotify.Object); // Write rezalt method AddNewContentInCart in actual3 var actual3 = service.AddInCart(objContentCart.Id, 1); // Verification rezalt with neсуssary number Assert.AreEqual((long)5, actual1); //Assert.AreEqual((long)5, actual2); Assert.AreEqual((long)6, actual3.Id); }
public void Add_New_Content_In_Cart_If_Not_Save_In_Repository() { var notifyDto = new NotificationDto(); // Setup Mock Product mockNotify.Setup(item => item.AddToCartNotify(It.IsAny <AddToCartNotifyDto>())) .Returns(() => notifyDto); // Create object Product var product = new Product() { Id = 1 }; // Setup Mock Product mockProduct.Setup(item => item.Get(It.IsAny <long>())) .Returns(() => product); // Create object ContentCart var objContentCart = new ContentCart() { Id = 5 }; var actual1 = objContentCart.Id; // Create List for search by content.Id List <ContentCart> contentCartList = new List <ContentCart>(); // Setup mock object mock.Setup(item => item.Find(It.IsAny <Expression <Func <ContentCart, bool> > >())) .Returns(() => contentCartList); mock.Setup(repo => repo.Add(It.IsAny <ContentCart>())) .Returns(() => null); // Create CartService object with mock.Object and mockProduct.Object var service = new CartService(mock.Object, mockProduct.Object, mockNotify.Object); // Write rezalt method AddNewContentInCart in actual3 Assert.Throws <AddContentInCartExceptions>(() => service.AddInCart(objContentCart.Id, 1)); }