我以前没有使用 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'?