??????????Test #2????????????????????Test #1?????????????????????????????????????Test #2?У??????????????????????????ProductPresenter???????????????????????

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

    public void Initialize() 
    { 
        string productID = View.ProductID; 
        Product product = _productService.GetByID(productID); 
        
        if (product != null) 
        { 
            View.Product = product; 
            View.IsInBasket = _basketService.ProductExists(productID); 
        } 
        else
        { 
           NavigationService.GoTo("/not-found"); 
        } 
    }

?????????????????View?? ProductService?? BasketService and NavigationService??????Щ????????????????????????????????????????????????????д???????????????????????????????????????

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

???????????????????????????????ProductPresenter??MockProductPresenter??

    public class MockProductPresenter 
    { 
        public IBasketService BasketService { get; set; } 
        public IProductService ProductService { get; set; } 
        public ProductPresenter Presenter { get; private set; } 
        
        public MockProductPresenter(IProductView view) 
        { 
            var productService = Mock.Create<IProductService>(); 
            var navigationService = Mock.Create<INavigationService>(); 
            var basketService = Mock.Create<IBasketService>(); 
        
            // Setup for private methods 
            Mock.Arrange(() => productService.GetByID("spr-product")).Returns(new Product()); 
            Mock.Arrange(() => basketService.ProductExists("spr-product")).Returns(true); 
            Mock.Arrange(() => navigationService.GoTo("/not-found")).OccursOnce(); 
        
            Presenter = new ProductPresenter( 
                                       view?? 
                                            navigationService?? 
                                            productService?? 
                                            basketService); 
        } 
    }

???????View.ProductID???????????????????????????????????MockProductPresenter?????????????????????View??????????????????????ID????????ж??????????????

?????????????????????????????????е???????????????????????????????Initialize????????product==null???????

    [TestMethod] 
    public void InitializeWithInvalidProductIDRedirectsToNotFound() 
    { 
        // Arrange 
        var view = Mock.Create<IProductView>(); 
        Mock.Arrange(() => view.ProductID).Returns("invalid-product"); 
        
        var mock = new MockProductPresenter(view); 
        
        // Act 
        mock.Presenter.Initialize(); 
        
        // Assert 
        Mock.Assert(mock.Presenter.NavigationService); 
    }

?????????????ЩProductPresenter????????????????????????????????????