public void GetAllAvailableQuizzesTest() { model.GetAllAvailableQuizzes(); List <Quiz> listOfAllQuizzes = model.ListOfAllQuizes; Assert.AreEqual(listOfAllQuizzes.First().Title, "Test Quiz"); }
public ActionResult Index(QuizViewModel model) { if (model.SearchByQuizTitle == null) { model = new QuizViewModel(); model.GetAllAvailableQuizzes(); } else { List <Quiz> newList = new List <Quiz>(); newList.Add(model.GetQuizByTitle(model.SearchByQuizTitle)); model.ListOfAllQuizes = newList; } return(View(model)); }
public void AddQuiz(Quiz newQuizItem) { bool alreadyExists = QuizEntities.Quizs.Any(x => x.Title == newQuizItem.Title); if (alreadyExists == false) { quizViewModel.GetAllAvailableQuizzes(); var listOfAllQuizzes = quizViewModel.ListOfAllQuizes; var selectedCategory = QuizEntities.Categories.Where(m => m.Title == newQuizItem.Category.Title).Single(); newQuizItem.Category = selectedCategory; newQuizItem.CategoryId = selectedCategory.Id; newQuizItem.Id = listOfAllQuizzes.Last().Id + 1; newQuizItem.DateCreated = DateTime.Now; QuizEntities.Quizs.Add(newQuizItem); QuizEntities.SaveChanges(); } }
public void AddQuizTest() { Quiz newQuiz = new Quiz() { DateCreated = DateTime.Now, Title = "New Test Quiz", Description = "New Test Description", Author = "Aoife", PassMark = 40, Category = entities.Categories.Where(x => x.Id == 1).Single() }; admin.AddQuiz(newQuiz); model.GetAllAvailableQuizzes(); List <Quiz> quizzes = model.ListOfAllQuizes; Assert.AreEqual(quizzes.Last().Title, "New Test Quiz"); }