??????????????????Щ???????е????????κ?????? GetProducts()???????????????????IProductRepository??????????????????????ò???????????????ó???????????——???????????????????????????????????????????

???????????????????????????ò?д??????????????????????????????????????????????????????????????????JustMock??????????????????????

??????????????????????????????????????????????????????

    [TestMethod] 
    public void GetProductWithValidIDReturnsProduct() 
    { 
        // Arrange 
        IProductRepository productRepository = Mock.Create<IProductRepository>(); 
        Mock.Arrange(() => productRepository.GetByID("spr-product")).Returns(new Product()); 
        ProductService productService = new ProductService(productRepository); 
        
        // Act 
        Product product = productService.GetByID("spr-product"); 
        
        // Assert 
        Assert.IsNotNull(product); 
    } 
        
    [TestMethod] 
    public void GetProductWithInValidIDThrowsException() 
    { 
        // Arrange 
        IProductRepository productRepository = Mock.Create<IProductRepository>(); 
        ProductService productService = new ProductService(productRepository); 
        
        // Act & Assert 
        Assert.Throws<ProductNotFoundException>(() => productService.GetByID("invalid-id")); 
    }

????????????????д???????????????????????д?????????49%?????????????????????????????28?У????????????57?С???????????????????????????????????

????2??????????????????

????????????????????????е????????????????????÷?????????????????????????????????????????????????????????????????????????????????????????????????????????????????

????Test #1

    TestMethod] 
    public void InitializeWithValidProductIDReturnsView() 
    { 
        // Arrange 
        IProductView productView = Mock.Create<IProductView>(); 
        Mock.Arrange(() => productView.ProductID).Returns("spr-product"); 
        
        IProductService productService = Mock.Create<IProductService>(); 
        Mock.Arrange(() => productService.GetByID("spr-product")).Returns(new Product()).OccursOnce(); 
        
        INavigationService navigationService = Mock.Create<INavigationService>(); 
        Mock.Arrange(() => navigationService.GoTo("/not-found")); 
        
        IBasketService basketService = Mock.Create<IBasketService>(); 
        Mock.Arrange(() => basketService.ProductExists("spr-product")).Returns(true); 
            
        var productPresenter = new ProductPresenter( 
                                                productView?? 
                                                navigationService?? 
                                                productService??  
                                                basketService); 
        
        // Act 
        productPresenter.Initialize(); 
        
        // Assert 
        Assert.IsNotNull(productView.Product); 
        Assert.IsTrue(productView.IsInBasket); 
    }

????Test #2

    [TestMethod] 
    public void InitializeWithValidProductIDReturnsView() 
    { 
        // Arrange    
        var view = Mock.Create<IProductView>(); 
        Mock.Arrange(() => view.ProductID).Returns("spr-product"); 
        
        var mock = new MockProductPresenter(view); 
        
        // Act 
        mock.Presenter.Initialize(); 
        
        // Assert 
        Assert.IsNotNull(mock.Presenter.View.Product); 
        Assert.IsTrue(mock.Presenter.View.IsInBasket); 
    }