// GridView1_RowEditing protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { //PanelGrid.Visible = false; //PanelDriveDetail.Visible = true; int itemID = (int)GridView1.DataKeys[e.NewEditIndex].Value; MealController.DeleteMeal(itemID); Response.Redirect(Globals.NavigateURL(TabId)); //MealController controller = new MealController(); //MealInfo item = controller.MealGetDrive(this.ModuleId, itemID); //if (item != null) //{ // // Response.Write(item); // txtDriveName.Text = item.DriveName; // txtDriveDate.Text = item.DriveDate.ToShortDateString(); // txtDriveNotes.Text = item.Description; // txtReminder.Text = item.Reminder; // txtPledgeLetter.Text = item.PledgeLetter; // isActive.SelectedIndex = Convert.ToInt32(item.IsActive); // HiddenItemID.Value = item.DriveID.ToString(); //} //else //{ // HiddenItemID.Value = ""; //} }
public void CantDeleteWithEaters() { Mock <IMealRepository> mock = new Mock <IMealRepository>(); Mock <IUserRepository> UserMock = new Mock <IUserRepository>(); ApplicationUser User = new ApplicationUser() { Firstname = "Arno", Lastname = "Broeders" }; Meal Meal5 = new Meal() { ID = 5, Cook = User, Date = DateTime.Now.AddDays(2), MaxAmountOfGuests = 1, Price = 2.40, Title = "Superdeal", Description = "Superdeal" }; User.MealsAsCook.Add(Meal5); mock.Setup(m => m.Meals).Returns(new List <Meal>() { Meal5 }); mock.Setup(m => m.JoinMeal(It.IsAny <int>(), It.IsAny <string>())).Returns((int meal, string user) => { if (Meal5.Eaters.Count < Meal5.MaxAmountOfGuests) { Meal5.Eaters.Add(new MealStudent()); return(true); } return(false); }); mock.Setup(m => m.DeleteMeal(It.IsAny <int>())).Returns((int meal) => { if (Meal5.Eaters.Count == 0) { return(true); } return(false); }); MealController Controller = new MealController(mock.Object, UserMock.Object); RedirectResult DeletedMeal = Controller.DeleteMeal(new StudentenHuis.Models.ViewModels.MealButtonViewModel() { MealID = 5 }) as RedirectResult; Assert.Equal("/Meal", DeletedMeal?.Url ?? ""); Controller.JoinMeal(new StudentenHuis.Models.ViewModels.MealButtonViewModel() { MealID = 5, }); ViewResult ViewResult = Controller.DeleteMeal(new StudentenHuis.Models.ViewModels.MealButtonViewModel() { MealID = 5, }) as ViewResult; Assert.Equal("Error", ViewResult?.ViewName ?? ""); }