public void TestRateLunchMenuInteractorUpdateReview() { var menmuDate = DateTime.Now.Date; var menu = new Menu(menmuDate); menu.AddMenuCourse("Test Course 1"); menu.AddMenuCourse("Test Course 2"); int reviewToken = 1; var courceId1 = menu.Courses[0].Id; menu.AddUpdateReview(courceId1, reviewToken, 1); var reviews = new List <(int courseId, int reviewScore)> { (courceId1, 2), }; var menuRepo = new Mock <IMenuRepo>(); menuRepo.Setup(x => x.GetById(It.IsAny <int>())).Returns(menu); var interactor = new RateMenuInteractor(menuRepo.Object); var response = interactor.Handle(new Contracts.Dtos.RateMenuRequest(menu.Id, reviewToken, reviews)); Assert.True(response.Result); Assert.True(menu.Courses.First().CourseReviews.Count() == 1); Assert.True(menu.Courses.First().CourseReviews.First().ReviewScore == 2); } }
public void TestRateLunchMenuInteractorReviewToSmall() { var menmuDate = DateTime.Now.Date; var menu = new Menu(menmuDate); menu.AddMenuCourse("Test Course 1"); int reviewToken = 1; var courceId1 = menu.Courses[0].Id; var reviews = new List <(int courseId, int reviewScore)> { (courceId1, -1) }; var menuRepo = new Mock <IMenuRepo>(); menuRepo.Setup(x => x.GetById(It.IsAny <int>())).Returns(menu); var interactor = new RateMenuInteractor(menuRepo.Object); var response = interactor.Handle(new Contracts.Dtos.RateMenuRequest(menu.Id, reviewToken, reviews)); Assert.False(response.Result); Assert.Contains(response.Messages, e => e == $"Unable to register review for cource with id: {courceId1} and score {-1}"); }
public IActionResult Index(MenuViewModel model) { if (ModelState.IsValid && model.Id.HasValue) { var interactor = new RateMenuInteractor(lunchMenuRepo); var ratings = model.Courses.Select(c => (c.Id, c.ReviewScore)).ToList(); var response = interactor.Handle(new Core.Contracts.Dtos.RateMenuRequest(model.Id.Value, model.ReviewToken, ratings)); if (response.Result) { model.Answered = true; model.Errors.Clear(); } else { model.Errors = response.Messages; } var menu = lunchMenuRepo.GetById(model.Id.Value); model.MenuRating = menu.AverageMenuReviewScore; foreach (var cource in model.Courses) { cource.ReviewScoreAverage = menu.Courses.Single(c => c.Id == cource.Id).AverageCourseReviewScore; } } return(View(model)); }