本文整理匯總了C#中CarController.Index方法的典型用法代碼示例。如果您正苦於以下問題:C# CarController.Index方法的具體用法?C# CarController.Index怎麽用?C# CarController.Index使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類CarController
的用法示例。
在下文中一共展示了CarController.Index方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Index_GetCar
public void Index_GetCar()
{
var expectedResult = new[]
{
new CarModel
{
CarId = 1,
Name = "Foo",
Color = "FooColor",
Price = 11111,
InventoryCount = 1,
Manufacturer = new ManufacturerModel
{
ManufacturerId = 1,
Country = "FooCountry",
Name = "FooManu"
}
}
};
var mockService = new Mock<ICarService>(MockBehavior.Strict);
mockService.Setup(s => s.GetCar(expectedResult[0].CarId)).Returns(expectedResult[0]);
var mockMapper = new Mock<Mappers.IMapper>(MockBehavior.Strict);
mockMapper.Setup(m => m.Map(expectedResult, typeof(IEnumerable<CarModel>), typeof(IEnumerable<CarViewModel>)));
var controller = new CarController(mockService.Object, mockMapper.Object);
var result = controller.Index(false, expectedResult[0].CarId) as ViewResult;
var model = result.Model as CarModel[];
Assert.IsNotNull(model);
mockService.Verify(foo => foo.GetCar(expectedResult[0].CarId));
}