public ActionResult ListRelatedCodeType(string starttype, string listtype, bool exact = false, int max = 0) { PageTitle = "List Related Code Type"; var model = new ListRelatedCodeTypeViewModel(); model.Overview = new Infrastructure.ViewModels.ContentViewModel().AddTitle("List RelatedCode Type").AddParagraph("List all related code table types. The list will begin with the start related code type if one is entered."); if (!string.IsNullOrEmpty(listtype)) // startType can be null: !string.IsNullOrEmpty(starttype) && { model.StartRelatedTableType = starttype; model.ListType = listtype; model.ExactLookup = exact; model.MaxRows = max; var listTypeChar = '\0'; char.TryParse(listtype, out listTypeChar); var results = AdwAdminService.GetRelatedListCodeTypes(model.StartRelatedTableType, listTypeChar, model.ExactLookup, model.MaxRows); model.Results = results.ToPagableRelatedCodeTypeViewModel(); if (model.Results == null || (model.Results != null && !model.Results.Any())) { AddInformationMessage("No results returned."); } } return(View(model)); }
public void ListRelatedCodeType_PostRedirectedToGet() { // Arrange var controller = SystemUnderTest(); var viewModel = new ListRelatedCodeTypeViewModel() { StartRelatedTableType = "A", ListType = "A", MaxRows = 1, ExactLookup = true }; var codeModel = new CodeModel { Code = "ABCD", ShortDescription = "Short Description", Description = "LongDescription" }; IList <CodeModel> models = new List <CodeModel>() { codeModel }; mockAdwAdminService.Setup(m => m.GetListCodes(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <int>(), It.IsAny <bool>())).Returns(models); // Act var result = controller.ListRelatedCodeType(viewModel) as RedirectToRouteResult; // Assert Assert.IsNotNull(result, "Redirect To Route Result must not be null."); if (result != null) { Assert.AreEqual("ListRelatedCodeType", result.RouteValues["action"]); } }
public void ListRelatedCodeType_Post() { // Arrange var controller = SystemUnderTest(); var viewModel = new ListRelatedCodeTypeViewModel() { }; controller.ModelState.AddModelError("", "SomeError"); // Act var result = controller.ListRelatedCodeType(viewModel) as ViewResult; // Assert Assert.IsNotNull(result, "View Result must not be null."); }
public ActionResult ListRelatedCodeType(ListRelatedCodeTypeViewModel model) { if (ModelState.IsValid) { RouteValueDictionary routeValues = new RouteValueDictionary(); if (!string.IsNullOrEmpty(model.StartRelatedTableType)) { routeValues.Add("starttype", model.StartRelatedTableType); } routeValues.Add("listtype", model.ListType ?? "C"); routeValues.Add("exact", model.ExactLookup); routeValues.Add("max", model.MaxRows); return(RedirectToAction(actionName: "ListRelatedCodeType", routeValues: routeValues)); } return(View(model)); }