?????????????????????
???????????? ???????[ 2013/3/15 10:56:41 ] ????????
??????????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????????????????????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11