以前に単体テストに MvcContrib を使用したことがなく、一部のテストの実行に少し問題があります。
次のテスト方法があります。
[TestMethod]
public void Create_GET_Route_Maps_To_Action()
{
RouteData getRouteData = "~/Interface/Pages/Create".WithMethod(HttpVerbs.Get);
getRouteData.DataTokens.Add("Popup", "true");
getRouteData.DataTokens.Add("WebDirectoryId", "99");
getRouteData.DataTokens.Add("LocaleId", "88");
getRouteData.DataTokens.Add("LayoutId", "77");
getRouteData.ShouldMapTo<PagesController>(c => c.Create(true, 99, 88, 77));
}
私のコントローラーの次のメソッドに一致するもの
[HttpGet]
[Popup]
public ViewResult Create(bool? popup, int? webDirectoryId, int? localeId, int? layoutId)
{
PageCreateViewModel pageCreateViewModel = new PageCreateViewModel
{
WebDirectories = GetChildDirectories(pageService.GetAllDirectories().Where(d => d.IsActive).Where(d => d.ParentId == null), ""),
Layouts = Mapper.Map<List<SelectListItem>>(pageService.GetAllLayouts().OrderBy(l => l.Filename)),
Locales = localizationService.GetAllLocales().Where(l => l.IsActive).OrderBy(l => l.LocaleName).Select(l => new SelectListItem { Text = string.Format("{0} ({1})", l.LocaleName, l.IETFLanguageTag), Value = l.LocaleId.ToString() })
};
return View(pageCreateViewModel);
}
次のエラーが発生し、その理由がわかりません。
MvcContrib.TestHelper.AssertionException: Value for parameter 'popup' did not match: expected 'True' but was ''; no value found in the route context action parameter named 'popup' - does your matching route contain a token called 'popup'?