public async void Create_ReturnsCreated() { // Arrange var controller = new MealController(_mealService.Object, _mapper); var expected = GetSampleMeal(); var sampleMeal = new InputMealDto { Name = expected.Name, TypeId = expected.TypeId }; _mealService.Setup(mock => mock.CreateAsync(It.IsAny <Meal>())).ReturnsAsync(expected); // Act var result = await controller.Create(sampleMeal); // Assert _mealService.Verify(mock => mock.CreateAsync(It.IsAny <Meal>()), Times.Once); var createdResult = Assert.IsType <CreatedAtActionResult>(result); var meal = Assert.IsType <MealDto>(createdResult.Value); Assert.Equal(expected.Id, meal.Id); Assert.Equal(expected.Name, meal.Name); Assert.Equal(expected.TypeId, meal.Type.Id); }
public void InsertTest() { // Arrange UserController controlleru = new UserController(); // Act List <User> loadAllU = controlleru.Get() as List <User>; //grab first result User u = loadAllU[0]; // Arrange FoodController controllerf = new FoodController(); // Act List <Food> loadAllF = controllerf.Get() as List <Food>; Meal m = new Meal { UserId = u.Id, Description = "Breakfast", FoodItems = loadAllF, Time = System.DateTime.Now }; // Arrange MealController controller = new MealController(); // Act int result = controller.Post(m); // Assert Assert.IsTrue(result > 0); }
public void Meals_ShouldRenderMealsViewModel() { // Arrange Mapper.Initialize(cfg => { cfg.CreateMap <Meal, MealViewModel>(); cfg.CreateMap <MealViewModel, Meal>(); }); var mockedMapper = new Mock <IMapper>(); var mockedMealsService = new Mock <IMealService>(); var mockedOrdersService = new Mock <IOrderService>(); var controller = new MealController(mockedMealsService.Object, mockedMapper.Object, mockedOrdersService.Object); var meal = new Meal { Id = Guid.NewGuid() }; var mealsCollection = new List <Meal>() { meal }; mockedMealsService.Setup(c => c.GetAll()).Returns(mealsCollection.AsQueryable()); //Act and Assert controller .WithCallTo(c => c.Meals()) .ShouldRenderView("Meals"); }
// 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 Add_ShouldRedirectToIndexHome() { // Arrange Mapper.Initialize(cfg => { cfg.CreateMap <Meal, MealViewModel>(); cfg.CreateMap <MealViewModel, Meal>(); }); var mockedMapper = new Mock <IMapper>(); var mockedMealsService = new Mock <IMealService>(); var mockedOrdersService = new Mock <IOrderService>(); var controller = new MealController(mockedMealsService.Object, mockedMapper.Object, mockedOrdersService.Object); var mealModel = new MealViewModel() { Title = "pesho", Image = "img", Price = 1, Content = "content" }; var meal = new Meal(); mockedMealsService.Setup(c => c.Add(meal)); //Act and Assert controller .WithCallTo(c => c.Add(mealModel)) .ShouldRedirectTo((HomeController c) => c.Index()); }
public void InsertTest() { Nutrient n = new Nutrient { Name = "Omega-3", Amount = 9000, Number = 1234, UnitName = "ug" }; List <Nutrient> nutrients = new List <Nutrient>(); nutrients.Add(n); // Arrange MealController controllerm = new MealController(); // Act List <Meal> loadAllM = controllerm.Get() as List <Meal>; //grab first result Meal meal = loadAllM[0]; Food f = new Food { FDCId = 999999, dataType = "test", description = "test", publicationDate = System.DateTime.Now, foodCode = "test", foodNutrients = nutrients, Quantity = 2, MealId = meal.Id }; // Arrange FoodController controller = new FoodController(); // Act int result = controller.Post(f); // Assert Assert.IsTrue(result > 0); }
public async void GetAll_ReturnsOk() { // Arrange var controller = new MealController(_mealService.Object, _mapper); var sampleMeals = new List <Meal>() { GetSampleMeal(), GetSampleMeal(), GetSampleMeal() }; _mealService.Setup(mock => mock.GetAsync()).ReturnsAsync(sampleMeals); // Act var result = await controller.GetAll(); // Assert _mealService.Verify(mock => mock.GetAsync(), Times.Once); var okObjectResult = Assert.IsType <OkObjectResult>(result);; var meals = Assert.IsAssignableFrom <IEnumerable <MealDto> >(okObjectResult.Value); Assert.Equal(sampleMeals.Count, meals.Count()); foreach (var meal in meals) { var expected = sampleMeals.SingleOrDefault(u => u.Id == meal.Id); Assert.Equal(expected.Name, meal.Name); Assert.Equal(expected.TypeId, meal.Type.Id); } }
public ucAddMeal(FoodController foodController, MealController mealController, User user) { this.foodController = foodController; this.mealController = mealController; this.user = user; InitializeComponent(); Initialize(); }
public void ShouldReturnScheduleForTwoWeeks() { // Arrange Mock <IMealRepository> mealMock = new Mock <IMealRepository>(); Mock <IStudentRepository> studentMock = new Mock <IStudentRepository>(); mealMock.Setup(m => m.Meals).Returns(new List <Meal>() { new Meal() { Id = 100, Title = "Compound - Strawberry", Description = " ", Price = 1.00, Date = DateTime.Now.AddDays(1) }, new Meal() { Id = 1, Title = "Chicken - White Meat With Tender", Description = "部è½æ ¼", Price = 1.00, Date = DateTime.Now.AddDays(2) }, new Meal() { Id = 2, Title = "Amarula Cream", Description = "1.00E+02", Price = 1.00, Date = DateTime.Now.AddDays(4) }, new Meal() { Id = 3, Title = "Cake - Cheese Cake 9 Inch", Description = "<>?:\"{}|_+", Price = 1.00, Date = DateTime.Now.AddDays(8) }, new Meal() { Id = 4, Title = "Crawfish", Description = "𠜎𠜱ð ¹ð ±“𠱸𠲖ð ³", Price = 1.00, Date = DateTime.Now.AddDays(16) }, new Meal() { Id = 5, Title = "Ham - Proscuitto", Description = " ", Price = 1.00, Date = DateTime.Now.AddDays(32) }, new Meal() { Id = 6, Title = "Soup - Campbells Bean Medley", Description = "1.00E+02", Price = 1.00, Date = DateTime.Now.AddDays(-1) }, new Meal() { Id = 7, Title = "Beef - Kobe Striploin", Description = "NULL", Price = 1.00, Date = DateTime.Now.AddDays(-4) }, new Meal() { Id = 8, Title = "Muffin Batt - Choc Chk", Description = "社會科å¸é™¢èªžå¸ç ”究所", Price = 1.50, Date = DateTime.Now.AddDays(-8) }, new Meal() { Id = 9, Title = "Bread - Italian Roll With Herbs", Description = "123", Price = 1.00, Date = DateTime.Now.AddDays(-16) } }); MealController controller = new MealController(mealMock.Object, studentMock.Object); // Act List <Meal> model = (controller.Index() as ViewResult)?.ViewData.Model as List <Meal>; // Assert Assert.Equal(4, model.Count); }
public ucLogin(UserController userController, MealController mealController, FoodController foodController, VitaminController vitaminController) { this.userController = userController; this.mealController = mealController; this.foodController = foodController; this.vitaminController = vitaminController; InitializeComponent(); }
public ucHomePage(MealController mealController, FoodController foodController, VitaminController vitaminController, User user) { this.mealController = mealController; this.foodController = foodController; this.vitaminController = vitaminController; this.user = user; InitializeComponent(); Initialize(); }
public void CannotJoinWhenMaxGuestsIsReached() { // Arrange Mock <IMealRepository> mealMock = new Mock <IMealRepository>(); Mock <IStudentRepository> studentMock = new Mock <IStudentRepository>(); Student student = new Student() { FirstName = "Ginni", LastName = "Wassell" }; Meal meal = new Meal() { Id = 100, Cook = student, Title = "Compound - Strawberry", Description = " ", Price = 1.50, Date = DateTime.Now.AddDays(6), MaxGuests = 1, }; student.CookAtMeals.Add(meal); mealMock.Setup(m => m.Meals).Returns(new List <Meal>() { meal }); mealMock.Setup(m => m.Join(It.IsAny <int>(), It.IsAny <string>())).Returns((int mealId, string studentId) => { if (meal.Guests.Count < meal.MaxGuests) { meal.Guests.Add(new Guest()); return(true); } return(false); }); MealController controller = new MealController(mealMock.Object, studentMock.Object); // Act controller.Join(new MealButtonViewModel() { MealId = 100 }); ViewResult viewResult = controller.Join(new MealButtonViewModel() { MealId = 100 }) as ViewResult; // Assert Assert.Equal("Error", viewResult?.ViewName); }
public void IndexReturnsListOfItems() { 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) }; User.MealsAsCook.Add(Meal5); mock.Setup(m => m.Meals).Returns(new List <Meal>() { new Meal() { ID = 0, Title = "Prachtmaaltijd", Description = "Prachtbeschrijving", Price = 0.25, Date = DateTime.Now.AddDays(4) }, new Meal() { ID = 1, Title = "Supermaaltijd", Description = "Superbeschrijving", Price = 0.85, Date = DateTime.Now.AddDays(2) }, new Meal() { ID = 2, Title = "Machtige maaltijd", Description = "Machtige beschrijving", Price = 0.55, Date = DateTime.Now.AddDays(7) }, new Meal() { ID = 3, Title = "Z maaltijd", Description = "Z beschrijving", Price = 0.45, Date = DateTime.Now.AddDays(5) }, new Meal() { ID = 4, Title = "Maaltijd van lang geleden", Date = DateTime.Now.AddDays(-1) }, Meal5 }); MealController meals = new MealController(mock.Object, UserMock.Object); List <Meal> list = meals.Index().ViewData.Model as List <Meal>; Assert.Equal(5, list.Count); Assert.Equal("Prachtmaaltijd", list[0].Title); Assert.Equal("Prachtbeschrijving", list[0].Description); Assert.Equal("Z maaltijd", list[3].Title); Assert.NotEqual("Maaltijd van lang geleden", list[4].Title); Assert.Equal("Arno", list[4].Cook.Firstname); Assert.Equal("Broeders", list[4].Cook.Lastname); Assert.Equal(1, list[4].Cook.MealsAsCook.Count); Assert.Equal(0.45, list[3].Price); }
public async Task Update_ReturnsBadrequest_WhenMealIsNull() { // Arrange var classUnderTest = new MealController(_mealService.Object, _mapper); // Act var res = await classUnderTest.Update(Guid.NewGuid(), null); // Assert Assert.IsType <BadRequestResult>(res); }
private void Initialize() { ConnectionPostgres conn = new ConnectionPostgres("127.0.0.1", "5432", "postgres", "a.123456", "mealprep"); UserController userController = new UserController(new UserDao(conn)); FoodController foodController = new FoodController(new FoodDao(conn)); MealController mealController = new MealController(new MealDao(conn), new FoodDao(conn)); VitaminController vitaminController = new VitaminController(new VitaminDao(conn)); this.Controls.Add(new ucLoginPage(userController, mealController, foodController, vitaminController)); UsefulAlgorithms.AdjustFormSize(this); }
public void LoadTest() { // Arrange MealController controller = new MealController(); // Act IEnumerable <Meal> result = controller.Get() as IEnumerable <Meal>; // Assert Assert.IsNotNull(result); }
public void FillGrid() { try { GridView1.DataSource = MealController.GetAllMeals(ModuleId); GridView1.DataBind(); } catch (Exception ex) { Exceptions.ProcessModuleLoadException(this, ex); } }
public void FillGrid() { try { GridViewSummaryReport.DataSource = MealController.Report(this.ModuleId, txtStartDate.Text.ToString(), txtEndDate.Text.ToString()); GridViewSummaryReport.DataBind(); } catch (Exception ex) { Exceptions.ProcessModuleLoadException(this, ex); } }
private MealController CreateMealController() { FakeFoodDao foodDao = new FakeFoodDao(); FakeMealDao mealDao = new FakeMealDao(); FoodController foodController = new FoodController(foodDao); foodController.AddFood(FOOD); MealController mealController = new MealController(mealDao, foodDao); return(mealController); }
public void MealController_ShouldThrowWhenOrdersServiceIsNull() { // Arrange var mockedMapper = new Mock <IMapper>(); var mockedMealsService = new Mock <IMealService>(); var mockedOrdersService = new Mock <IOrderService>(); MealController controller; // Act && Assert Assert.Throws <ArgumentNullException>(() => controller = new MealController(mockedMealsService.Object, mockedMapper.Object, null)); }
public void CannotEditMealWithNoTitle() { Mock <IMealRepository> mealMock = new Mock <IMealRepository>(); Mock <IStudentRepository> studentMock = new Mock <IStudentRepository>(); Meal meal = new Meal() { Id = 100, Title = null, Description = " ", Price = 1.50, Date = DateTime.Now.AddDays(-1), MaxGuests = 1 }; mealMock.Setup(m => m.Meals).Returns(new List <Meal>() { meal }); mealMock.Setup(m => m.Create(It.IsAny <Meal>())).Returns((Meal model) => { if (meal.Date > DateTime.Now) { return(true); } return(false); }); mealMock.Setup(m => m.Update(It.IsAny <Meal>())).Returns((Meal model) => { if (meal.Title != null && meal.MaxGuests > 0 && meal.Price >= 0) { return(true); } return(false); }); MealController controller = new MealController(mealMock.Object, studentMock.Object); // Act controller.Create(meal); meal.Title = null; ViewResult viewResult = controller.Edit(meal) as ViewResult; // Assert Assert.Null(viewResult.ViewName); }
public void CantJoinWithManyEaters() { 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); }); MealController Controller = new MealController(mock.Object, UserMock.Object); RedirectResult Result = Controller.JoinMeal(new StudentenHuis.Models.ViewModels.MealButtonViewModel() { MealID = 5, }) as RedirectResult; Assert.Equal("/Meal", Result?.Url ?? ""); ViewResult ViewResult = Controller.JoinMeal(new StudentenHuis.Models.ViewModels.MealButtonViewModel() { MealID = 5, }) as ViewResult; Assert.Equal("Error", ViewResult?.ViewName ?? ""); }
public void DetailPageWorks() { 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) }; User.MealsAsCook.Add(Meal5); mock.Setup(m => m.Meals).Returns(new List <Meal>() { new Meal() { ID = 0, Title = "Prachtmaaltijd", Description = "Prachtbeschrijving", Price = 0.25, Date = DateTime.Now.AddDays(4) }, new Meal() { ID = 1, Title = "Supermaaltijd", Description = "Superbeschrijving", Price = 0.85, Date = DateTime.Now.AddDays(2) }, new Meal() { ID = 2, Title = "Machtige maaltijd", Description = "Machtige beschrijving", Price = 0.55, Date = DateTime.Now.AddDays(7) }, new Meal() { ID = 3, Title = "Z maaltijd", Description = "Z beschrijving", Price = 0.45, Date = DateTime.Now.AddDays(5) }, new Meal() { ID = 4, Title = "Maaltijd van lang geleden", Date = DateTime.Now.AddDays(-1) }, Meal5 }); MealController meals = new MealController(mock.Object, UserMock.Object); Meal Meal = meals.Detail(0).ViewData.Model as Meal; Assert.Equal("Prachtmaaltijd", Meal.Title); Assert.Equal("Prachtbeschrijving", Meal.Description); Assert.Equal(0.25, Meal.Price); }
public async Task Update_ReturnsNotFound_WhenMealNotExists() { // Arrange var controller = new MealController(_mealService.Object, _mapper); var sampleMeal = GetSampleInputMealDto(); _mealService.Setup(mock => mock.UpdateAsync(It.IsAny <Meal>())).ReturnsAsync((Meal)null); // Act var result = await controller.Update(Guid.NewGuid(), sampleMeal); // Assert _mealService.Verify(mock => mock.UpdateAsync(It.IsAny <Meal>()), Times.Once); Assert.IsType <NotFoundResult>(result); }
public async void Delete_WhenIdNotExists_ShouldReturnNotFound() { var mealService = new Mock <IMealService>(); var classUnderTest = new MealController(mealService.Object, _mapper); var id = Guid.NewGuid(); mealService.Setup(a => a.DeleteByIdAsync(It.Is <Guid>(g => g == id))) .ReturnsAsync(0); var result = await classUnderTest.Delete(id); Assert.IsType <NotFoundResult>(result); mealService.VerifyAll(); }
public async Task Get_ReturnsNotFound_WhenMealNotExists() { // Arrange var controller = new MealController(_mealService.Object, _mapper); var mealId = Guid.NewGuid(); _mealService.Setup(mock => mock.GetByIdAsync(mealId)).ReturnsAsync((Meal)null); // Act var result = await controller.Get(mealId); // Assert _mealService.Verify(mock => mock.GetByIdAsync(mealId), Times.Once); Assert.IsType <NotFoundResult>(result); }
/// <summary> /// This button on click method is for adding a new Meal to the database. /// Added April 13. Modification of Meal's Add method. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void AddMealButton_Click(object sender, EventArgs e) { //finding the customer profile choice to display string addItem = AddMealsTextBox.Text.Trim(); int userID = Convert.ToInt32(Session["adminID"]); MessageUserControl.TryRun(() => { MealController sysmgr = new MealController(); sysmgr.AddMeal(addItem, userID); MealsListView.DataBind(); AddMealsTextBox.Text = ""; }, "Success", "Successfully added the new meal: \"" + addItem + "\""); }
public void AddTest() { // Arrange var userName = Guid.NewGuid().ToString(); var foodName = Guid.NewGuid().ToString(); var rnd = new Random(); var userController = new UserController(userName); var mealController = new MealController(userController.CurrentUser); var food = new Food(foodName, rnd.Next(50, 500), rnd.Next(50, 500), rnd.Next(50, 500), rnd.Next(50, 500)); //Act mealController.Add(food, 100); //Assert Assert.AreEqual(food.Name, mealController.Meal.Foods.First().Key.Name); }
public void UpdateTest() { // Arrange MealController controller = new MealController(); // Act List <Meal> loadAll = controller.Get() as List <Meal>; //grab first result Meal m = loadAll[0]; m.Description = "Lunch"; int results = controller.Post(m); Assert.IsTrue(results > 0); }
public void DeleteTest() { //always fails because There is a workout that depends on this Mealtype // Arrange MealController controller = new MealController(); // Act List <Meal> loadAll = controller.Get() as List <Meal>; //grab first result Meal m = loadAll[0]; int results = controller.Delete(m); Assert.IsTrue(results > 0); }