本文整理汇总了C#中ProductRepository.GetProductById方法的典型用法代码示例。如果您正苦于以下问题:C# ProductRepository.GetProductById方法的具体用法?C# ProductRepository.GetProductById怎么用?C# ProductRepository.GetProductById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProductRepository
的用法示例。
在下文中一共展示了ProductRepository.GetProductById方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetProductById_ProductDoesNotExist_ShouldReturnNull
public void GetProductById_ProductDoesNotExist_ShouldReturnNull()
{
using (var repository = new ProductRepository())
{
var actual = repository.GetProductById(1001);
Assert.IsNull(actual);
}
}
示例2: GetProductById_GetTestProduct_ShouldReturnExpectedValue
public void GetProductById_GetTestProduct_ShouldReturnExpectedValue()
{
using (var repository = new ProductRepository())
{
var actual = repository.GetProductById(2);
Assert.IsNotNull(actual);
Assert.AreEqual("Test Product 2", actual.Name);
Assert.AreEqual("Test Category", actual.Category);
}
}
示例3: HowToConfigurePipelineBehaviour
public void HowToConfigurePipelineBehaviour()
{
using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db())
{
// create a product to get from the repository
object expectedProduct = new object();
string productId = "1";
// configure Pipeline Watcher to expect a pipeline call where the args Custom Data
// contains ProductId equals "1". Once the args received the pipeline result is set
// to the Product Custom Data property
db.PipelineWatcher
.WhenCall("findProductById")
.WithArgs(a => a.CustomData["ProductId"].Equals(productId))
.Then(a => a.CustomData["Product"] = expectedProduct);
// create a repository and call get product method
ProductRepository repository = new ProductRepository();
var actualProduct = repository.GetProductById(productId);
// assert the received product is the same as the expected one
Xunit.Assert.Equal(expectedProduct, actualProduct);
}
}
示例4: HowDoIConfigureThePipelineBehaviour
public void HowDoIConfigureThePipelineBehaviour()
{
using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db())
{
// create a product to get from the repository
object expectedProduct = new object();
// configure processing of the pipeline arguments. Will set the 'expectedProduct' instance
// to CustomData["Product"] property only when the CustomData["ProductId"] is "1"
string productId = "1";
// configure a pipeline watcher to expect a pipeline call where the args custom data contains
// ProductId. Once the args received the pipeline result is set into Product custom data property
db.PipelineWatcher
.WhenCall("findProductById")
.WithArgs(a => a.CustomData["ProductId"].Equals(productId))
.Then(a => a.CustomData["Product"] = expectedProduct);
// create a repository and call get product method
ProductRepository repository = new ProductRepository();
var actualProduct = repository.GetProductById(productId);
// assert the received product is the same as the expected one
Assert.Equal(expectedProduct, actualProduct);
}
}