public void TestViewMyProductDetails_ServiceReturnsProduct_ShouldCallFactoryCreateProductDetailsViewModel(int id) { var mockedView = new Mock <IProductDetailsView>(); mockedView.Setup(v => v.Model).Returns(new ProductDetailsViewModel()); var mockedProvider = new Mock <IAuthenticationProvider>(); var category = new Category(); var product = new Models.Product { Category = category }; var mockedService = new Mock <IProductRatingService>(); var mockedProductService = new Mock <IProductService>(); mockedProductService.Setup(s => s.GetById(It.IsAny <int>())) .Returns(product); var mockedFactory = new Mock <IViewModelFactory>(); var presenter = new ProductDetailsPresenter(mockedView.Object, mockedProductService.Object, mockedFactory.Object, mockedService.Object, mockedProvider.Object); var args = new ProductDetailsEventArgs(id); mockedView.Raise(v => v.MyProductDetails += null, args); mockedFactory.Verify(f => f.CreateProductDetailsViewModel(product.ProductId, product.Name, category.Name, product.Price, product.Volume, product.Maker, product.ImageMimeType, product.ImageBuffer), Times.Once); }
public void TestOnRatingProduct_ShouldGetProviderIdCorrectly( int rating, string content, int productId, string userId) { var mockedView = new Mock <IProductDetailsView>(); mockedView.Setup(v => v.Model).Returns(new ProductDetailsViewModel()); var mockedProvider = new Mock <IAuthenticationProvider>(); mockedProvider.Setup(v => v.CurrentUserId).Returns(userId); var mockedService = new Mock <IProductRatingService>(); mockedService.Setup( s => s.CreateProductRating(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <string>())) .Returns(new Models.ProductRating()); var mockedProductService = new Mock <IProductService>(); var mockedFactory = new Mock <IViewModelFactory>(); var presenter = new ProductDetailsPresenter(mockedView.Object, mockedProductService.Object, mockedFactory.Object, mockedService.Object, mockedProvider.Object); var args = new RateProductEventArgs(rating, content, productId); mockedView.Raise(v => v.RateProduct += null, args); mockedProvider.Verify(p => p.CurrentUserId, Times.Once); }
public void TestViewMyProductDetails_ServiceReturnsNull_ShouldNotCallFactoryCreateProductDetailsViewModel(int id) { var mockedView = new Mock <IProductDetailsView>(); mockedView.Setup(v => v.Model).Returns(new ProductDetailsViewModel()); var mockedProvider = new Mock <IAuthenticationProvider>(); var mockedService = new Mock <IProductRatingService>(); var mockedProductService = new Mock <IProductService>(); var mockedFactory = new Mock <IViewModelFactory>(); var presenter = new ProductDetailsPresenter(mockedView.Object, mockedProductService.Object, mockedFactory.Object, mockedService.Object, mockedProvider.Object); var args = new ProductDetailsEventArgs(id); mockedView.Raise(v => v.MyProductDetails += null, args); mockedFactory.Verify(f => f.CreateProductDetailsViewModel(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <decimal>(), It.IsAny <double>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <byte[]>()), Times.Never()); }
public void TestConstructor_PassEverythingCorrectly_ShouldInitializeCorrectly() { var mockedView = new Mock <IProductDetailsView>(); var mockedProductService = new Mock <IProductService>(); var mockedFactory = new Mock <IViewModelFactory>(); var mockedProductRatingService = new Mock <IProductRatingService>(); var mockedAuthenticationProvider = new Mock <IAuthenticationProvider>(); var presenter = new ProductDetailsPresenter(mockedView.Object, mockedProductService.Object, mockedFactory.Object, mockedProductRatingService.Object, mockedAuthenticationProvider.Object); Assert.IsNotNull(presenter); }
public void OnViewLoadedTest() { MockProductDetailsView mockView = new MockProductDetailsView(); SharePointServiceLocator.ReplaceCurrentServiceLocator(new ActivatingServiceLocator() .RegisterTypeMapping <IProductCatalogRepository, MockProductCatalogRepository>() .RegisterTypeMapping <ILogger, MockLogger>()); ProductDetailsPresenter target = new ProductDetailsPresenter(mockView); target.LoadProduct("123456"); Assert.AreEqual("Widget", mockView.Product.Name); Assert.AreEqual("Widget Description", mockView.Product.LongDescription); Assert.AreEqual("123456", mockView.Product.Sku); Assert.IsTrue(mockView.DataBindCalled); }
public void TestViewMyProductDetails_ShouldCallServiceGetById(int id) { var mockedView = new Mock <IProductDetailsView>(); mockedView.Setup(v => v.Model).Returns(new ProductDetailsViewModel()); var mockedProvider = new Mock <IAuthenticationProvider>(); var mockedService = new Mock <IProductRatingService>(); var mockedProductService = new Mock <IProductService>(); var mockedFactory = new Mock <IViewModelFactory>(); var presenter = new ProductDetailsPresenter(mockedView.Object, mockedProductService.Object, mockedFactory.Object, mockedService.Object, mockedProvider.Object); var args = new ProductDetailsEventArgs(id); mockedView.Raise(v => v.MyProductDetails += null, args); mockedProductService.Verify(s => s.GetById(id), Times.Once); }
/// <summary> /// Create an instance of the <see cref="ProductDetailsControl"/> /// </summary> public ProductDetailsControl() { // Create the presenter that hosts the logic for this view. this.presenter = new ProductDetailsPresenter(this); }