?????????????????????
???????????? ???????[ 2013/3/15 10:56:41 ] ????????
??????????????????Щ???????е????????κ?????? 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);
}
??????
???·???
??????????????????
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