/// <summary> /// Constructor used to initialize object properties at construction. /// </summary> /// <param name="userModels">List of users that will be displayed on an admin view page.</param> /// <param name="roleList">List of the system roles that will be used in a dropdown box</param> /// <param name="selectedRole">Selected role to default the drop down list to.</param> public AdminViewModel(List<UserInfoModel> userModels, SelectList roleList, string selectedRole) { if(userModels != null && userModels.Count > 0 && roleList != null && roleList.Count() > 0 && !string.IsNullOrEmpty(selectedRole)) { Users = userModels; RoleList = roleList; SelectedRole = selectedRole; } }
// GET: Settings/Create public ActionResult Create() { sdtoUser userDetails = UtilityHelper.UserSession.GetSession(UtilityHelper.UserSession.LoggedInUser); if (userDetails == null) userDetails = new sdtoUser(); var items = new SelectList(db.Companies, "CompanyId", "CompanyName"); ViewBag.CompanyList = items; if (items == null || items.Count() == 0) { TempData["ERR_PREMATURE_MESSAGE"] = "Please register a company for configuring settings"; return RedirectToAction("Create", "Company"); } var settings = db.GeneralSettings.Where(x => x.CompanyId == userDetails.CompanyId); if (settings != null && settings.Count() > 0) return EditOnCreate(settings.FirstOrDefault(x => x.CompanyId == userDetails.CompanyId) as sdtoSettings); else return View(new sdtoSettings() { CompanyId = userDetails.CompanyId, BankCharges = 0, BankInterest = 0 }); }
public void EditTestLockError() { // Arrange db = new touch_for_foodEntities(); Order_ItemController target = new Order_ItemController(); int expected = orderItem1.id; orderItem1.version += 5; SelectList expectedMenuList = new SelectList(db.menu_item, "id", "id", orderItem1.menu_item_id); SelectList expectedOrderList = new SelectList(db.orders, "id", "id", orderItem1.order_id); ViewResult actual; // Act actual = (ViewResult)target.Edit(orderItem1); // Assert Assert.AreEqual(expected, ((order_item)actual.ViewData.Model).id); SelectList actualMenuList = actual.ViewBag.menu_item_id; Assert.AreEqual(expectedMenuList.GetType(), actualMenuList.GetType()); Assert.AreEqual(expectedMenuList.Count(), actualMenuList.Count()); SelectList actualOrderList = actual.ViewBag.order_id; Assert.AreEqual(expectedOrderList.GetType(), actualOrderList.GetType()); Assert.AreEqual(expectedOrderList.Count(), actualOrderList.Count()); string errorMsg = actual.ViewBag.Error; Assert.IsNotNull(errorMsg); //error message is sent to view }
public void CreateViewTest() { //Arrange db = new touch_for_foodEntities(); RestaurantUserController target = new RestaurantUserController(); SelectList expectedRestoList = new SelectList(db.restaurants, "id", "name"); SelectList expectedUsersList = new SelectList(db.users.Where(u => u.user_role == (int)SiteRoles.Restaurant || u.user_role == (int)SiteRoles.Admin), "id", "username"); ViewResult actual; //Act actual = (ViewResult)target.Create(); //Assert SelectList actualRestoList = actual.ViewBag.restaurant_id; Assert.AreEqual(expectedRestoList.GetType(), actualRestoList.GetType()); Assert.AreEqual(expectedRestoList.Count(), actualRestoList.Count()); SelectList actualUserList = actual.ViewBag.user_id; Assert.AreEqual(expectedUsersList.GetType(), actualUserList.GetType()); Assert.AreEqual(expectedUsersList.Count(), actualUserList.Count()); }
public void CreateViewTest() { //Arrange db = new touch_for_foodEntities(); Order_ItemController target = new Order_ItemController(); SelectList expectedMenuList = new SelectList(db.menu_item, "id", "id"); SelectList expectedOrderList = new SelectList(db.orders, "id", "id"); ViewResult actual; //Act actual = (ViewResult)target.Create(); //Assert SelectList actualMenuList = actual.ViewBag.menu_item_id; Assert.AreEqual(expectedMenuList.GetType(), actualMenuList.GetType()); Assert.AreEqual(expectedMenuList.Count(), actualMenuList.Count()); SelectList actualOrderList = actual.ViewBag.order_id; Assert.AreEqual(expectedOrderList.GetType(), actualOrderList.GetType()); Assert.AreEqual(expectedOrderList.Count(), actualOrderList.Count()); }
public void CreateTestInvalidStateModel() { // Arrange db = new touch_for_foodEntities(); Menu_ItemController target = new Menu_ItemController(); target.ModelState.AddModelError("error", "ModelState is invalid"); SelectList expectedItemList = new SelectList(db.items, "id", "name", menuItem2.item_id); SelectList expectedCategoryList = new SelectList(db.menu_category, "id", "id", menuItem2.menu_category_id); ViewResult actual; // Act actual = (ViewResult)target.Create(menuItem2); // Assert SelectList actualItemList = actual.ViewBag.item_id; Assert.AreEqual(expectedItemList.GetType(), actualItemList.GetType()); Assert.AreEqual(expectedItemList.Count(), actualItemList.Count()); SelectList actualCategoryList = actual.ViewBag.menu_category_id; Assert.AreEqual(expectedCategoryList.GetType(), actualCategoryList.GetType()); Assert.AreEqual(expectedCategoryList.Count(), actualCategoryList.Count()); string errorMsg = actual.ViewBag.Error; Assert.IsNotNull(errorMsg); //error message is sent to view }
public void EditTestLockFailure() { // Arrange db = new touch_for_foodEntities(); Menu_ItemController target = new Menu_ItemController(); int expected = menuItem1.id; SelectList expectedItemList = new SelectList(db.items, "id", "name", menuItem1.item_id); SelectList expectedCategoryList = new SelectList(db.menu_category, "id", "id", menuItem1.menu_category_id); ViewResult actual; menuItem1.version += 5; // Act actual = (ViewResult)target.Edit(menuItem1); // Assert Assert.AreEqual(expected, ((menu_item)actual.ViewData.Model).id); SelectList actualItemList = actual.ViewBag.item_id; Assert.AreEqual(expectedItemList.GetType(), actualItemList.GetType()); Assert.AreEqual(expectedItemList.Count(), actualItemList.Count()); SelectList actualCategoryList = actual.ViewBag.menu_category_id; Assert.AreEqual(expectedCategoryList.GetType(), actualCategoryList.GetType()); Assert.AreEqual(expectedCategoryList.Count(), actualCategoryList.Count()); string errorMsg = actual.ViewBag.Error; Assert.IsNotNull(errorMsg); //error message is sent to view }
public void CreateViewTest() { //Arrange db = new touch_for_foodEntities(); SelectList expectedRestoList = new SelectList(db.restaurants, "id", "name", db.restaurants.First().id); //Act ViewResult actual = (ViewResult)target.Create(); //Assert Assert.AreEqual(expectedRestoList.GetType(), actual.ViewBag.resto_id.GetType()); SelectList actualRestoList = actual.ViewBag.resto_id; Assert.AreEqual(expectedRestoList.Count(), actualRestoList.Count()); }
public ActionResult DropInspectors(int id, FormCollection form) { try { Store store = db.Stores.Find(id); int InspectorID; int.TryParse(Request.Form["User_UserID"], out InspectorID); //获取要被删除的检查员的用户ID User Inspector = db.Users.Find(InspectorID); store.Inspectors.Remove(Inspector); db.Entry(store).State = EntityState.Modified; db.SaveChanges(); //方便连续删除检查员,提示删除成功后,停留DropInspectors视图,同时返回未被删除的Inspectors SelectList Inspectors = new SelectList(store.Inspectors.ToList(), "UserID", "UserName"); if (Inspectors.Count() == 0) Inspectors = null; ViewBag.User_UserID = Inspectors; ViewData["Statue"] = "Drop Inspector" + Inspector.UserName + " succeed"; return View(store); } catch (Exception) { ModelState.AddModelError("", "Server Error."); } return RedirectToAction("Index"); }
public void EditTestInvalidStateModel() { // Arrange db = new touch_for_foodEntities(); FriendshipController target = new FriendshipController(); long expected = friendship1.id; SelectList expectedUser1List = new SelectList(db.users, "id", "username", user1); SelectList expectedUser2List = new SelectList(db.users, "id", "username", user2); friendship1.second_user = user3.id; target.ModelState.AddModelError("error", "ModelState is invalid"); // Act ViewResult actual = (ViewResult)target.Edit(friendship1); // Assert SelectList actualUser1List = actual.ViewBag.first_user; SelectList actualUser2List = actual.ViewBag.second_user; string errorMsg = actual.ViewBag.Error; Assert.AreEqual(((friendship)actual.Model).id, expected); Assert.AreEqual(expectedUser1List.GetType(), actualUser1List.GetType()); Assert.AreEqual(expectedUser2List.GetType(), actualUser2List.GetType()); Assert.AreEqual(expectedUser1List.Count(), actualUser1List.Count()); Assert.AreEqual(expectedUser2List.Count(), actualUser2List.Count()); Assert.IsNotNull(errorMsg); //error message is sent to view }
public async Task<ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email, FullName = model.FullName, Status = UserStatus.Offline }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { var currentUser = UserManager.FindByName(user.UserName); var roleresult = UserManager.AddToRole(currentUser.Id, model.Role.ToString()); await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return RedirectToAction("Index", "Home"); } AddErrors(result); } // If we got this far, something failed, redisplay form var adminUsers = UserManager.Users.Where(u => u.Roles.Any(r => r.RoleId == "2")).ToList(); var selectListUser = new SelectList(adminUsers, "Id", "FullName"); if (selectListUser.Count() == 0) { List<SelectListItem> items = new List<SelectListItem>(); var emptyItem = new SelectListItem() { Text = "None", Value = "" }; items.Add(emptyItem); selectListUser = new SelectList(adminUsers, "Value", "Text"); } ViewBag.AdminUsers = selectListUser; return View(model); }
public void EditTest() { //Setup int expected = table1.id; SelectList expectedRestoList = new SelectList(db.restaurants, "id", "name", table1.restaurant_id); //Act ViewResult actual = (ViewResult)target.Edit(table1.id); //Assert Assert.AreEqual(((table)actual.Model).id, expected); Assert.AreEqual(expectedRestoList.GetType(), actual.ViewBag.restaurant_id.GetType()); SelectList actualRestoList = actual.ViewBag.restaurant_id; Assert.AreEqual(expectedRestoList.Count(), actualRestoList.Count()); }
public void CreateViewTest() { //Arrange db = new touch_for_foodEntities(); FriendshipController target = new FriendshipController(); SelectList expectedUserList = new SelectList(db.users, "id", "username"); //Act ViewResult actual = (ViewResult)target.Create(); //Assert SelectList actualUser1List = actual.ViewBag.first_user; SelectList actualUser2List = actual.ViewBag.second_user; Assert.AreEqual(expectedUserList.GetType(), actualUser1List.GetType()); Assert.AreEqual(expectedUserList.GetType(), actualUser2List.GetType()); Assert.AreEqual(expectedUserList.Count(), actualUser1List.Count()); Assert.AreEqual(expectedUserList.Count(), actualUser2List.Count()); }
public void EditTableTestInvalidStateModel() { // Arrange db = new touch_for_foodEntities(); target.ModelState.AddModelError("error", "ModelState is invalid"); int expected = table1.id; SelectList expectedRestos = new SelectList(db.restaurants, "id", "name", table1.restaurant_id); ViewResult actual; // Act actual = (ViewResult)target.Edit(table1); // Assert Assert.AreEqual(expected, ((table)actual.ViewData.Model).id); SelectList actualRestos = actual.ViewBag.restaurant_id; Assert.AreEqual(expectedRestos.GetType(), actualRestos.GetType()); Assert.AreEqual(expectedRestos.Count(), actualRestos.Count()); string errorMsg = actual.ViewBag.Error; Assert.IsNotNull(errorMsg); //error message is sent to view }
public void EditViewTest() { //Arrange db = new touch_for_foodEntities(); SelectList expectedRestoList = new SelectList(db.restaurants, "id", "name", menu1.id); //Act ViewResult actual = (ViewResult)target.Edit(menu1.id); //Assert Assert.AreEqual(((menu)actual.Model).id, menu1.id); Assert.AreEqual(expectedRestoList.GetType(), actual.ViewBag.resto_id.GetType()); SelectList actualRestoList = actual.ViewBag.resto_id; Assert.AreEqual(expectedRestoList.Count(), actualRestoList.Count()); }
public void EditVersionErrorTest() { //Arrange db = new touch_for_foodEntities(); SelectList expectedRestoList = new SelectList(db.restaurants, "id", "name", menu1.id); string changeString = "UnitTesting"; menu1.version += 5; menu1.name = changeString; //Act var actual = target.Edit(menu1) as ViewResult; //Assert db = new touch_for_foodEntities(); Assert.IsFalse(db.menus.Find(menu1.id).name.Equals(changeString)); Assert.AreEqual(((menu)actual.Model).id, menu1.id); Assert.AreEqual(expectedRestoList.GetType(), actual.ViewBag.resto_id.GetType()); SelectList actualRestoList = actual.ViewBag.resto_id; Assert.AreEqual(expectedRestoList.Count(), actualRestoList.Count()); }
public void EditViewTest() { // Arrange db = new touch_for_foodEntities(); Order_ItemController target = new Order_ItemController(); int expected = orderItem1.id; SelectList expectedMenuList = new SelectList(db.menu_item, "id", "id", orderItem1.menu_item_id); SelectList expectedOrderList = new SelectList(db.orders, "id", "id", orderItem1.order_id); ViewResult actual; // Act actual = (ViewResult)target.Edit(orderItem1.id); // Assert Assert.AreEqual(expected, ((order_item)actual.ViewData.Model).id); SelectList actualMenuList = actual.ViewBag.menu_item_id; Assert.AreEqual(expectedMenuList.GetType(), actualMenuList.GetType()); Assert.AreEqual(expectedMenuList.Count(), actualMenuList.Count()); SelectList actualOrderList = actual.ViewBag.order_id; Assert.AreEqual(expectedOrderList.GetType(), actualOrderList.GetType()); Assert.AreEqual(expectedOrderList.Count(), actualOrderList.Count()); }
public ActionResult DropEmployees(int id, FormCollection form) { try { Store store = db.Stores.Find(id); int EmployeeID; int.TryParse(Request.Form["User_UserID"], out EmployeeID); User Employee = db.Users.Find(EmployeeID); store.Employees.Remove(Employee); db.Entry(store).State = EntityState.Modified; db.SaveChanges(); //方便连续删除检查员,提示删除成功后,停留DropEmployees视图,同时返回未被删除的Employees SelectList Employees = new SelectList(store.Employees.ToList(), "UserID", "UserName"); if (Employees.Count() == 0) Employees = null; ViewBag.User_UserID = Employees; ViewData["Statue"] = "Drop Employee" + Employee.UserName + " succeed"; return View(store); } catch (Exception) { ModelState.AddModelError("", "Server Error."); } return RedirectToAction("Index"); }
public void EditViewTest() { //Arrange db = new touch_for_foodEntities(); FriendshipController target = new FriendshipController(); long expected = friendship1.id; SelectList expectedUser1List = new SelectList(db.users, "id", "username", user1); SelectList expectedUser2List = new SelectList(db.users, "id", "username", user2); //Act ViewResult actual = (ViewResult)target.Edit(friendship1.id); //Assert SelectList actualUser1List = actual.ViewBag.first_user; SelectList actualUser2List = actual.ViewBag.second_user; Assert.AreEqual(((friendship)actual.Model).id, expected); Assert.AreEqual(expectedUser1List.GetType(), actualUser1List.GetType()); Assert.AreEqual(expectedUser2List.GetType(), actualUser2List.GetType()); Assert.AreEqual(expectedUser1List.Count(), actualUser1List.Count()); Assert.AreEqual(expectedUser2List.Count(), actualUser2List.Count()); }
public void CreateTestInvalidStateModel() { // Arrange db = new touch_for_foodEntities(); target.ModelState.AddModelError("error", "ModelState is invalid"); SelectList expectedRestoList = new SelectList(db.restaurants, "id", "name", menu1.resto_id); ViewResult actual; // Act actual = (ViewResult)target.Create(menu1); // Assert SelectList actualRestoList = actual.ViewBag.resto_id; Assert.AreEqual(expectedRestoList.GetType(), actualRestoList.GetType()); Assert.AreEqual(expectedRestoList.Count(), actualRestoList.Count()); string errorMsg = actual.ViewBag.Error; Assert.IsNotNull(errorMsg); //error message is sent to view }
///get:/Store/DropEmployees/5 /// <summary> /// 删除检查员 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult DropEmployees(int? id) { if (id.HasValue) { Store store = db.Stores.Find(id); SelectList Employees = new SelectList(store.Employees.ToList(), "UserID", "UserName"); if (Employees.Count() == 0) Employees = null; ViewBag.User_UserID = Employees; return View(store); } return RedirectToAction("Index"); }
public void EditViewTest() { // Arrange db = new touch_for_foodEntities(); SideController target = new SideController(); int expected = side1.id; SelectList expectedSideList = new SelectList(db.menu_category, "id", "id", side1.menu_category_id); ViewResult actual; // Act actual = (ViewResult)target.Edit(side1.id); // Assert Assert.AreEqual(expected, ((side)actual.ViewData.Model).id); SelectList actualSideList = actual.ViewBag.menu_category_id; Assert.AreEqual(expectedSideList.GetType(), actualSideList.GetType()); Assert.AreEqual(expectedSideList.Count(), actualSideList.Count()); }
///get:/Store/DropInspectors/5 /// <summary> /// 删除检查员 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult DropInspectors(int? id) { if (id.HasValue) { Store store = db.Stores.Find(id); SelectList Inspectors = new SelectList(store.Inspectors.ToList(), "UserID", "UserName"); if (Inspectors.Count() == 0) Inspectors = null; ViewBag.User_UserID = Inspectors; return View(store); } return RedirectToAction("Index"); }
public void CreateViewTest() { //Arrange db = new touch_for_foodEntities(); SelectList expectedCategoryList = new SelectList(db.categories, "id", "name"); ViewResult actual; //Act actual = (ViewResult)target.Create(); //Assert SelectList actualCategoryList = actual.ViewBag.category_id; Assert.AreEqual(expectedCategoryList.GetType(), actualCategoryList.GetType()); Assert.AreEqual(expectedCategoryList.Count(), actualCategoryList.Count()); }
// // GET: //Payment public PartialViewResult Payment(int id = 0) { int nPaymentNo = 0; int nCustomerId = 0; int nPos = -1; int nHas = 0; double dSalesAmount = 0; double dTax = 0; double dTotalTax = 0; double dTotalAmount = 0; double dBalanceDue = 0; string szError = ""; string szDecriptedData = ""; string szMsg = ""; string szCustomerNo = ""; Payments payment = null; InitialInfo initialinfo = null; Customers customer = null; List<KeyValuePair<string, string>> listSelector = new List<KeyValuePair<string, string>>(); //Get sales order SalesOrder salesorder = db.SalesOrders.Find(id); if (salesorder != null) { //Get the totals GetSalesOrderTotals(salesorder.SalesOrderId, ref dSalesAmount, ref dTotalTax, ref dTax, ref dTotalAmount, ref dBalanceDue); customer = db.Customers.Where(cst => cst.Id == salesorder.CustomerId).FirstOrDefault<Customers>(); if (customer != null) { //Get the next payment No initialinfo = db.InitialInfoes.FirstOrDefault<InitialInfo>(); if (initialinfo == null) { initialinfo = new InitialInfo(); initialinfo.InvoiceNo = 0; initialinfo.PaymentNo = 1; initialinfo.PurchaseOrderNo = 0; initialinfo.SalesOrderNo = 0; initialinfo.TaxRate = 0; db.InitialInfoes.Add(initialinfo); } else { nPaymentNo = initialinfo.PaymentNo; nPaymentNo++; initialinfo.PaymentNo = nPaymentNo; db.Entry(initialinfo).State = EntityState.Modified; } db.SaveChanges(); //Get Payment Type listSelector = new List<KeyValuePair<string, string>>(); var qryPaymentType = db.CustomersCardTypes.OrderBy(cdty => cdty.CardType); if (qryPaymentType.Count() > 0) { foreach (var item in qryPaymentType) { listSelector.Add(new KeyValuePair<string, string>(item.CardType, item.CardType)); } } SelectList paymentTypeselectorlist = new SelectList(listSelector, "Key", "Value"); //Get the Credit Card Number for each credit card listSelector = new List<KeyValuePair<string, string>>(); if (paymentTypeselectorlist.Count() > 0) { foreach (var item in paymentTypeselectorlist) { var qryPayment = db.CustomersCreditCardShippings.Join(db.Customers, ctcc => ctcc.CustomerId, cstm => cstm.Id, (ctcc, cstm) => new { ctcc, cstm }).OrderBy(Nctad => Nctad.ctcc.CardType).ThenBy(Nctad => Nctad.ctcc.CreditNumber).Where(Nctad => Nctad.ctcc.CustomerId == customer.Id && Nctad.ctcc.CardType == item.Value); if (qryPayment.Count() > 0) { foreach (var itemCard in qryPayment) { if (nCustomerId == 0) { nCustomerId = itemCard.cstm.Id; } //Decode card number szError = ""; szDecriptedData = TimelyDepotMVC.Controllers.PaymentController.DecodeInfo02(itemCard.ctcc.CreditNumber, ref szError); if (!string.IsNullOrEmpty(szError)) { nPos = szError.IndexOf("data to decode"); if (nPos != -1) { szDecriptedData = string.Empty; } else { szDecriptedData = string.Format("******"); } } else { //Mask the card number nHas = szDecriptedData.Length; if (nHas > 4) { szMsg = szDecriptedData.Substring(nHas - 4, 4); szDecriptedData = string.Format("******{0}", szMsg); } else { szDecriptedData = string.Format("******"); } } szMsg = string.Format("{0} - {1}", itemCard.ctcc.CardType, szDecriptedData); listSelector.Add(new KeyValuePair<string, string>(itemCard.ctcc.CreditNumber, szMsg)); } } } } SelectList cardsselectorlist = new SelectList(listSelector, "Key", "Value"); ViewBag.CardsList = cardsselectorlist; payment = new Payments(); payment.PaymentNo = nPaymentNo.ToString(); payment.PaymentDate = DateTime.Now; payment.CustomerNo = customer.CustomerNo; payment.SalesOrderNo = salesorder.SalesOrderNo; payment.Amount = Convert.ToDecimal(dBalanceDue); //db.Payments.Add(payment); //db.SaveChanges(); } } return PartialView(payment); }
public void EditBillTestLockError() { // Arrange db = new touch_for_foodEntities(); BillController target = new BillController(); SelectList expectedOrderList = new SelectList(db.orders, "id", "id", bill1.order_id); ViewResult actual; bill1.version += 5; // Act actual = (ViewResult)target.Edit(bill1); // Assert SelectList actualOrderList = actual.ViewBag.order_id; Assert.AreEqual(expectedOrderList.GetType(), actualOrderList.GetType()); Assert.AreEqual(expectedOrderList.Count(), actualOrderList.Count()); string errorMsg = actual.ViewBag.Error; Assert.IsNotNull(errorMsg); //error message is sent to view }
public void CreateViewTest() { //Arrange db = new touch_for_foodEntities(); Menu_ItemController target = new Menu_ItemController(); SelectList expectedItemList = new SelectList(db.items, "id", "name"); SelectList expectedCategoryList = new SelectList(db.menu_category, "id", "id"); ViewResult actual; //Act actual = (ViewResult)target.Create(); //Assert SelectList actualItemList = actual.ViewBag.item_id; Assert.AreEqual(expectedItemList.GetType(), actualItemList.GetType()); Assert.AreEqual(expectedItemList.Count(), actualItemList.Count()); SelectList actualCategoryList = actual.ViewBag.menu_category_id; Assert.AreEqual(expectedCategoryList.GetType(), actualCategoryList.GetType()); Assert.AreEqual(expectedCategoryList.Count(), actualCategoryList.Count()); }
public void CreateTestInvalidStateModel() { // Arrange db = new touch_for_foodEntities(); Order_ItemController target = new Order_ItemController(); target.ModelState.AddModelError("error", "ModelState is invalid"); SelectList expectedMenuList = new SelectList(db.menu_item, "id", "id", orderItem3.menu_item_id); SelectList expectedOrderList = new SelectList(db.orders, "id", "id", orderItem3.order_id); ViewResult actual; // Act actual = (ViewResult)target.Create(orderItem3); // Assert SelectList actualMenuList = actual.ViewBag.menu_item_id; Assert.AreEqual(expectedMenuList.GetType(), actualMenuList.GetType()); Assert.AreEqual(expectedMenuList.Count(), actualMenuList.Count()); SelectList actualOrderList = actual.ViewBag.order_id; Assert.AreEqual(expectedOrderList.GetType(), actualOrderList.GetType()); Assert.AreEqual(expectedOrderList.Count(), actualOrderList.Count()); string errorMsg = actual.ViewBag.Error; Assert.IsNotNull(errorMsg); //error message is sent to view }
public void EditViewTest() { // Arrange db = new touch_for_foodEntities(); Menu_ItemController target = new Menu_ItemController(); int expected = menuItem1.id; SelectList expectedItemList = new SelectList(db.items, "id", "name", menuItem1.item_id); SelectList expectedCategoryList = new SelectList(db.menu_category, "id", "id", menuItem1.menu_category_id); ViewResult actual; // Act actual = (ViewResult)target.Edit(menuItem1.id); // Assert Assert.AreEqual(expected, ((menu_item)actual.ViewData.Model).id); SelectList actualItemList = actual.ViewBag.item_id; Assert.AreEqual(expectedItemList.GetType(), actualItemList.GetType()); Assert.AreEqual(expectedItemList.Count(), actualItemList.Count()); SelectList actualCategoryList = actual.ViewBag.menu_category_id; Assert.AreEqual(expectedCategoryList.GetType(), actualCategoryList.GetType()); Assert.AreEqual(expectedCategoryList.Count(), actualCategoryList.Count()); }
public void EditViewTest() { // Arrange db = new touch_for_foodEntities(); int expected = request1.id; SelectList expectedTableList = new SelectList(db.tables, "id", "name", request1.table_id); ViewResult actual; // Act actual = (ViewResult)target.Edit(request1.id); // Assert Assert.AreEqual(expected, ((service_request)actual.ViewData.Model).id); SelectList actualTableList = actual.ViewBag.table_id; Assert.AreEqual(expectedTableList.GetType(), actualTableList.GetType()); Assert.AreEqual(expectedTableList.Count(), actualTableList.Count()); }