本文整理汇总了C#中Framework.Inject方法的典型用法代码示例。如果您正苦于以下问题:C# Framework.Inject方法的具体用法?C# Framework.Inject怎么用?C# Framework.Inject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Framework
的用法示例。
在下文中一共展示了Framework.Inject方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: It_should_display_a_list_of_categories
public void It_should_display_a_list_of_categories()
{
// ARRANGE
var mvc = new Framework();
var repoStub = mvc.Inject<Mock<ICategoryRepository>>();
var categoriesActual = new List<Category> {mvc.New<Category>()};
repoStub.Setup(r => r.FindAll()).Returns(categoriesActual.AsQueryable());
// ACT
var result = mvc.HttpGet<HomeController, ViewResult>(c => c.Index());
var categoriesExpected = result.ActionResult.Model as List<Category>;
// ASSERT
Assert.That(categoriesExpected.Count, Is.EqualTo(1));
Assert.That(categoriesExpected[0].Id, Is.EqualTo(categoriesActual[0].Id));
}
示例2: It_should_display_no_categories_found_message
public void It_should_display_no_categories_found_message()
{
// ARRANGE
var mvc = new Framework();
var repoStub = mvc.Inject<Mock<ICategoryRepository>>();
IQueryable<Category> categories = null; // no items
repoStub.Setup(r => r.FindAll()).Returns(categories);
// ACT
var result = mvc.HttpGet<CategoryController, ViewResult>(c => c.Index());
// ASSERT
var viewModel = result.ActionResult.Model as IndexViewModel;
Assert.That(viewModel.GetNoCategoriesMessage(), Is.EqualTo("No categories found."));
}
示例3: It_should_display_a_list_of_categories
public void It_should_display_a_list_of_categories()
{
// ARRANGE
var mvc = new Framework();
var repoStub = mvc.Inject<Mock<ICategoryRepository>>();
var categoriesExpected = new List<Category>
{
new Category { Id = 123, Name = "category1" },
new Category { Id = 234, Name = "category2"}
};
repoStub.Setup(r => r.FindAll()).Returns(categoriesExpected.AsQueryable());
// ACT
var result = mvc.HttpGet<CategoryController, ViewResult>(c => c.Index());
// ASSERT
var viewModel = result.ActionResult.Model as IndexViewModel;
var categoriesActual = viewModel.Categories.ToArray();
Assert.That(categoriesActual.Length, Is.EqualTo(2));
Assert.That(categoriesActual[0].Id, Is.EqualTo(123));
Assert.That(categoriesActual[1].Id, Is.EqualTo(234));
}