?????????????????????
???????????? ???????[ 2013/3/15 10:56:41 ] ????????
??????????д??????????????????????????????д??????????????????Щ???????????д???????????????????????????????????и?????????????????????????????????С?????????????????bug?????Σ?????????????????Сbug?????????????????????????????????????????е???????д????????
?????????????????????????л????????????????????????????????????????????????????????????????ò???????????(TDD)????????“???”???????????????????????????????????????????Щ????????????????????????о??????????????????????????????????????????????????????????Щ?????????????????????????????????????????????????????????“????????????????????”????“??????????д?????????????”??
????????????????????????????
????д???????????????κ????????????粻д??
???????????????飬????????????????
?????????????????????????Ч?????????????б????
?????????????????????????????????Щ????????/?????????????????????????е???????????????????????????
????1????????????
?????????????????????????????????????????????????н??в????????ζ????????????????????????????????????????α????????ж?·???ò????????????????????
???????????????????????????е?GetByID??????
public class ProductService : IProductService
{
private readonly IProductRepository _productRepository;
public ProductService(IProductRepository productRepository)
{
this._productRepository = productRepository;
}
public Product GetByID(string id)
{
Product product = _productRepository.GetByID(id);
if (product == null)
{
throw new ProductNotFoundException();
}
return product;
}
}
????????ò?????????У????????д???IProductRepository???????????????ProductService.GetByID?????????????????С???????IProductRepository?????????????????????
[TestMethod]
public void GetProductWithValidIDReturnsProduct()
{
// Arrange
IProductRepository productRepository = new StubProductRepository();
ProductService productService = new ProductService(productRepository);
// Act
Product product = productService.GetByID("spr-product");
// Assert
Assert.IsNotNull(product);
}
public class StubProductRepository : IProductRepository
{
public Product GetByID(string id)
{
return new Product()
{
ID = "spr-product"??
Name = "Nice Product"
};
}
public IEnumerable<Product> GetProducts()
{
throw new NotImplementedException();
}
}
??????
???·???
??????????????????
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