public void TestConstructor_PassEverythingCorrectly_ShouldInitializeCorrectly() { var mockedView = new Mock <ICartSummaryView>(); var mockedShoppingCart = new Mock <IShoppingCart>(); var mockedFactory = new Mock <IViewModelFactory>(); var presenter = new CartSummaryPresenter(mockedView.Object, mockedShoppingCart.Object, mockedFactory.Object); Assert.IsNotNull(presenter); }
public void TestViewMyInit_ShouldSetViewModelTotalCorrectly(string name, int quantity, decimal price, double volume, string maker, string imageMimeType, string categoryName, int id, decimal total) { var imgBuffer = new byte[3]; var category = new Category(categoryName); var product = new Models.Product(name, category, quantity, price, volume, maker, imageMimeType, imgBuffer); var mockedView = new Mock <ICartSummaryView>(); mockedView.Setup(v => v.Model).Returns(new CartSummaryVIewModel()); var mockedCartLine = new Mock <ICartLine>(); mockedCartLine.Setup(c => c.Product).Returns(product); mockedCartLine.Setup(c => c.Quantity).Returns(quantity); var cartLines = new List <ICartLine> { mockedCartLine.Object }; var mockedShoppingCart = new Mock <IShoppingCart>(); mockedShoppingCart.Setup(c => c.CartLines).Returns(cartLines); mockedShoppingCart.Setup(c => c.ComputeTotal()).Returns(total); var productDetailsViewModel = new ProductDetailsViewModel { Id = id }; var cartLineViewModel = new CartLineViewModel(productDetailsViewModel, quantity); var mockedFactory = new Mock <IViewModelFactory>(); mockedFactory.Setup(f => f.CreateCartLineViewModel(It.IsAny <ProductDetailsViewModel>(), It.IsAny <int>())) .Returns(cartLineViewModel); var expectedResult = new List <CartLineViewModel> { cartLineViewModel }; var presenter = new CartSummaryPresenter(mockedView.Object, mockedShoppingCart.Object, mockedFactory.Object); mockedView.Raise(v => v.MyInit += null, EventArgs.Empty); Assert.AreEqual(total, mockedView.Object.Model.Total); }
public void TestViewMyInit_ShouldCallCartCartLines() { var mockedView = new Mock <ICartSummaryView>(); mockedView.Setup(v => v.Model).Returns(new CartSummaryVIewModel()); var mockedShoppingCart = new Mock <IShoppingCart>(); mockedShoppingCart.Setup(c => c.CartLines).Returns(new List <ICartLine>()); var mockedFactory = new Mock <IViewModelFactory>(); var presenter = new CartSummaryPresenter(mockedView.Object, mockedShoppingCart.Object, mockedFactory.Object); mockedView.Raise(v => v.MyInit += null, EventArgs.Empty); mockedShoppingCart.Verify(c => c.CartLines, Times.Once); }
public void TestViewRemoveFromCart_ShouldCallCartComputeTotal(int id) { var mockedView = new Mock <ICartSummaryView>(); mockedView.Setup(v => v.Model).Returns(new CartSummaryVIewModel()); var mockedShoppingCart = new Mock <IShoppingCart>(); var mockedFactory = new Mock <IViewModelFactory>(); var presenter = new CartSummaryPresenter(mockedView.Object, mockedShoppingCart.Object, mockedFactory.Object); var args = new DeleteProductEventArgs(id); mockedView.Raise(v => v.RemoveFromCart += null, args); mockedShoppingCart.Verify(c => c.ComputeTotal(), Times.Once); }