public void PostQuestion_NoRepresentative_NoQuestions() { int parliamentID = 1; var law1 = Helpers.CreateLaw(parliamentID, new List <string> { "AmirFazlic", "AsimSarajlic", "SalkoSokolovic" }, new List <string> { "First Question", "Second Question" }); var user = Helpers.CreateNewUser(); try { var service = new QuestionsService(); var model = service.GetQuestionsModel(law1.LawID, user.Id); model.Text = "Some Text"; service.PostQuestion(model, user.Id); var response = service.GetQuestionsForLaw(law1.LawID, user.Id); Assert.AreEqual(2, response.Questions.Count); } finally { Helpers.DeleteUser(user); } }
public ActionResult AskRepresentative(int lawId, AskLawQuestionModel model) { TryUpdateModel(model); QuestionsService service = new QuestionsService(); service.PostQuestion(model, User.Identity.GetUserId()); return(PartialView("Representatives/_AskRepresentativesSuccess")); }
public void GetQuestionsForLaw_ChainedMethods() { ApplicationDbContext context = null; var law = Helpers.CreateLaw(1, new List <string> { "AmirFazlic", "AsimSarajlic", "SalkoSokolovic" }, new List <string> { "First Question", "Second Question" }); var user1 = Helpers.CreateNewUser(); var user2 = Helpers.CreateNewUser(); try { var service = new QuestionsService(); var askmodel1 = service.GetQuestionsModel(law.LawID, user1.Id); askmodel1.SuggestedRepresentatives[0].IsSelected = true; askmodel1.SuggestedRepresentatives[1].IsSelected = true; askmodel1.Questions[0].IsSelected = true; service.PostQuestion(askmodel1, user1.Id); var askmodel2 = service.GetQuestionsModel(law.LawID, user2.Id); askmodel2.SuggestedRepresentatives[0].IsSelected = true; askmodel2.SuggestedRepresentatives[2].IsSelected = true; askmodel2.Questions[0].IsSelected = true; askmodel2.Text = "Test Custom Question"; service.PostQuestion(askmodel2, user2.Id); context = ApplicationDbContext.Create(); context.Answers.AddRange(new List <Answer> { new Answer { QuestionID = askmodel1.Questions[0].ID, RepresentativeID = askmodel1.SuggestedRepresentatives[0].ID, Text = "Test answer", AnsweredTimeUtc = DateTime.UtcNow } }); context.SaveChanges(); var response = service.GetQuestionsForLaw(law.LawID, user1.Id); Assert.IsNotNull(response.Law, "Law does not exist"); Assert.AreEqual(3, response.Questions.Count, "Questions.Count"); Assert.IsTrue(response.Questions[0].IsPredefined, "Predefined question not marked"); Assert.IsFalse(response.Questions[2].IsPredefined, "Custom question marked as predefined"); Assert.AreEqual(4, response.Questions[0].AskedCount, "First Question Asked times"); Assert.AreEqual(1, response.Questions[0].AnswersCount, "First Question answered times"); Assert.AreEqual(2, response.Questions[2].AskedCount, "Third question Asked times"); Assert.AreEqual(0, response.Questions[2].AnswersCount, "Third Question answered times"); Assert.AreEqual(3, response.Questions[0].Representatives.Count, "Reps on first question"); Assert.AreEqual(2, response.Questions[2].Representatives.Count, "Reps on custom question"); Assert.AreEqual(2, response.Questions[0].Representatives[0].AskedCount); Assert.AreEqual(1, response.Questions[0].Representatives[1].AskedCount); Assert.IsTrue(response.Questions[0].Representatives[0].Answered); Assert.AreEqual("Test answer", response.Questions[0].Representatives[0].Answer.Text); } finally { if (context != null) { context.Dispose(); } Helpers.DeleteLaw(law); Helpers.DeleteUser(user1); Helpers.DeleteUser(user2); } }
public void GetLatestAnswers_ChainMethods() { ApplicationDbContext context = null; var law = Helpers.CreateLaw(1, new List <string> { "AmirFazlic", "AsimSarajlic", "SalkoSokolovic" }, new List <string> { "First Question", "Second Question" }); var user1 = Helpers.CreateNewUser(); try { var service = new QuestionsService(); var askmodel1 = service.GetQuestionsModel(law.LawID, user1.Id); askmodel1.SuggestedRepresentatives[0].IsSelected = true; askmodel1.SuggestedRepresentatives[1].IsSelected = true; askmodel1.SuggestedRepresentatives[2].IsSelected = true; askmodel1.Questions[0].IsSelected = true; askmodel1.Questions[1].IsSelected = true; service.PostQuestion(askmodel1, user1.Id); context = ApplicationDbContext.Create(); context.Answers.AddRange(new List <Answer> { new Answer { QuestionID = askmodel1.Questions[0].ID, RepresentativeID = askmodel1.SuggestedRepresentatives[0].ID, Text = "Test answer 00", AnsweredTimeUtc = DateTime.UtcNow.AddMinutes(1) }, new Answer { QuestionID = askmodel1.Questions[0].ID, RepresentativeID = askmodel1.SuggestedRepresentatives[1].ID, Text = "Test answer 01", AnsweredTimeUtc = DateTime.UtcNow.AddMinutes(2) }, new Answer { QuestionID = askmodel1.Questions[0].ID, RepresentativeID = askmodel1.SuggestedRepresentatives[2].ID, Text = "Test answer 02", AnsweredTimeUtc = DateTime.UtcNow.AddMinutes(3) }, new Answer { QuestionID = askmodel1.Questions[1].ID, RepresentativeID = askmodel1.SuggestedRepresentatives[0].ID, Text = "Test answer 10", AnsweredTimeUtc = DateTime.UtcNow.AddMinutes(4) }, new Answer { QuestionID = askmodel1.Questions[1].ID, RepresentativeID = askmodel1.SuggestedRepresentatives[1].ID, Text = "Test answer 11", AnsweredTimeUtc = DateTime.UtcNow.AddMinutes(5) }, new Answer { QuestionID = askmodel1.Questions[1].ID, RepresentativeID = askmodel1.SuggestedRepresentatives[2].ID, Text = "Test answer 12", AnsweredTimeUtc = DateTime.UtcNow.AddMinutes(6) }, }); context.SaveChanges(); var response = service.GetLatestAnswersForLaw(law.LawID, user1.Id, 5); Assert.AreEqual(law.LawID, response.LawID, "Law ID"); Assert.AreEqual(5, response.Count, "Total question count"); Assert.IsNotNull(response.Answers, "Answers returned"); Assert.IsNotNull(response.Answers[0].Question, "Question populated"); Assert.IsNotNull(response.Answers[0].Representative, "Representative populated"); var selectedAnswer = response.Answers.Where(x => x.Question.Id == askmodel1.Questions[0].ID && x.Representative.ID == askmodel1.SuggestedRepresentatives[2].ID).First(); Assert.AreEqual("Test answer 02", selectedAnswer.Text); } finally { if (context != null) { context.Dispose(); } Helpers.DeleteLaw(law); Helpers.DeleteUser(user1); } }