public Mutation( ProjectService projectService, EvaluationService evaluationService, ParticipantService participantService, QuestionService questionService, AnswerService answerService, ActionService actionService, NoteService noteService, ClosingRemarkService closingRemarkService, QuestionTemplateService questionTemplateService, ProjectCategoryService projectCategoryService, IAuthService authService, ILogger <Mutation> logger ) { _projectService = projectService; _evaluationService = evaluationService; _participantService = participantService; _questionService = questionService; _answerService = answerService; _actionService = actionService; _noteService = noteService; _closingRemarkService = closingRemarkService; _questionTemplateService = questionTemplateService; _projectCategoryService = projectCategoryService; _authService = authService; _logger = logger; }
private void DisplayAnswer() { lv_testResult.Items.Clear(); QuestionService questionService = new QuestionService(); List <QuestionModel> questionList = questionService.GetAll().Where(x => x.TestID == testID).ToList(); AnswerService answerService = new AnswerService(); List <AnswerModel> answerList = answerService.GetAll().ToList(); UserService userService = new UserService(); lbl_userName.Text = userService.Get(userID).Name; StatisticService statisticService = new StatisticService(); int correct = statisticService.GetAll() .Where(x => x.TestID == testID && x.UserID == userID) .OrderByDescending(x => x.StatisticID) .First().CorrectAnswer; lbl_result.Text += Math.Round((double)(100 * correct) / questionList.Count).ToString() + "%"; foreach (var question in questionList) { string correctAnswer = answerList.Where(x => x.QuestionID == question.QuestionID && x.isCorrect == true).Single().AnswerText; var row = new string[] { question.QuestionName, correctAnswer }; ListViewItem listView = new ListViewItem(row); listView.Tag = question; lv_testResult.Items.Add(listView); } }
public void Add_answer_to_database() { var options = new DbContextOptionsBuilder <QuizDbContext>() .UseInMemoryDatabase(databaseName: "Add_answer_to_database") .Options; using (var context = new QuizDbContext(options)) { var service = new AnswerService(context); Answer a1 = new Answer { Content = "AAA", Id = 1, QuestionID = 12 }; Answer a2 = new Answer { Content = "BBB", Id = 2, QuestionID = 13 }; service.CreateAnswer(a1); service.CreateAnswer(a2); } using (var context = new QuizDbContext(options)) { var numberOfAnserwsInDb = context.Answer.Count(); numberOfAnserwsInDb.Should().Be(2); } }
private async void GoToRiddleList(object sender, EventArgs e) { var riddleService = new RiddleService(_baseApiAccessor); var answerService = new AnswerService(_settingsProvider, _baseApiAccessor); await Navigation.PushAsync(new RiddleListPage(riddleService, answerService)); }
public TrainingController() { ts = new TrainingService(); ls = new LessonService(); qs = new QuestionService(); ans = new AnswerService(); }
public TestController(ITestService testService, QuestionService questionService, AnswerService answerService, INotificationService notificationService) { this.testService = testService; this.questionService = questionService; this.answerService = answerService; this.notificationService = notificationService; }
public void CreateFollowUpAnswers() { ParticipantService participantService = new ParticipantService(fixture.context); QuestionService questionService = new QuestionService(fixture.context); AnswerService answerService = new AnswerService(fixture.context); ProjectService projectService = new ProjectService(fixture.context); Project project = projectService.Create("AnswerService_GetFromQuestionExists"); EvaluationService evaluationService = new EvaluationService(fixture.context); Evaluation evaluation = evaluationService.Create("AnswerService_GetFromQuestionExists", project, ""); Participant participant = participantService.Create("CreateFollowUpAnswers_id", evaluation, Organization.All, Role.Facilitator); QuestionTemplateService qts = new QuestionTemplateService(fixture.context); List <Question> questions = questionService.CreateBulk(qts.GetAll().ToList(), evaluation); answerService.Create(participant, questions[0], Severity.High, "test_answer_0", Progression.Workshop); answerService.Create(participant, questions[1], Severity.High, "test_answer_1", Progression.Workshop); answerService.Create(participant, questions[2], Severity.High, "test_answer_2", Progression.Workshop); int nAnswersFollowupBefore = answerService.GetAll().Where(a => (a.Progression.Equals(Progression.FollowUp) && a.Question.Evaluation.Equals(evaluation))).Count(); int nAnswersWorkshop = answerService.GetAll().Where(a => (a.Progression.Equals(Progression.Workshop) && a.Question.Evaluation.Equals(evaluation))).Count(); answerService.CreateFollowUpAnswers(evaluation); int nAnswersFollowup = answerService.GetAll().Where(a => (a.Progression.Equals(Progression.FollowUp) && a.Question.Evaluation.Equals(evaluation))).Count(); Assert.Equal(nAnswersFollowupBefore + nAnswersWorkshop, nAnswersFollowup); }
public async Task AnswerExistAsyncShouldReturnTrueIfAnswerExist() { // Arrange var db = Tests.GetDatabase(); var answer1 = new AnswerOption { Id = 1 }; var answer2 = new AnswerOption { Id = 2 }; var answer3 = new AnswerOption { Id = 3 }; await db.AddRangeAsync(answer1, answer2, answer3); await db.SaveChangesAsync(); var answerService = new AnswerService(db); // Act var result = await answerService.AnswerExistAsync(1); // Assert result .ShouldBeEquivalentTo(true); }
//delete question have to delete answers first public ActionResult DeleteQuestion(string questionId) { AnswerService answerService = new AnswerService(); QuestionService questionService = new QuestionService(); try { //delete answers foreach (var answer in answerService.findByQuestionId(questionId)) { if (answerService.deleteById(answer.ANSWER_ID.ToString()) == false) { return(RedirectToAction("ShowQuestions", "Manager")); } } if (questionService.deleteById(questionId)) { return(RedirectToAction("ShowQuestions", "Manager")); } else { throw new Exception(); } } catch (Exception ex) { throw new Exception(); } }
private AnswerService CreateAnswerService() { var userId = User.Identity.GetUserId(); var service = new AnswerService(userId); return(service); }
public ActionResult ShowAnswers(string questionId) { AnswerService answerService = new AnswerService(); ViewBag.AnswerList = answerService.findByQuestionId(questionId); return(View()); }
public IHttpActionResult Post([FromBody] SurveyData surveyData) { var answerService = new AnswerService(); answerService.UpdateAnswers(surveyData); return(Ok(surveyData)); }
public MutationTest() { ILoggerFactory factory = new NullLoggerFactory(); _projectService = new ProjectService(_context); _evaluationService = new EvaluationService(_context); _participantService = new ParticipantService(_context); _questionService = new QuestionService(_context); _answerService = new AnswerService(_context); _questionTemplateService = new QuestionTemplateService(_context); _actionService = new ActionService(_context); _noteService = new NoteService(_context); _mutation = new Mutation( _projectService, _evaluationService, _participantService, _questionService, _answerService, _questionTemplateService, _actionService, _noteService, new MockAuthService(), new Logger <Mutation>(factory) ); }
public QuestionViewModels GetQuestionContent() { var data = new QuestionViewModels(); var config = new ConfigService(); var answer = new AnswerService(); var block = new BlockService(); var menuService = new MenuService(); data.ListAnswerFeature = answer.GetListAnswer("").ToList(); data.BlockFooter = block.GetBlockBySection("5"); data.HotLineTitle = config.GetConfigById("HOTLINE_TITLE").Value; data.HotLine = config.GetConfigById("HOTLINE").Value; data.SiteMain = config.GetConfigById("SITE_MAIN").Value; data.ContactTitle = config.GetConfigById("CONTACT_TITLE").Value; data.CopyRight = config.GetConfigById("COPY_RIGHT").Value; data.QuestionTitle = config.GetConfigById("QUESTION_TITLE").Value; data.MenuListModel = menuService.GetListMenuView("1"); data.TitleMain = config.GetConfigById("TITLE_MAIN").Value; data.DescMain = config.GetConfigById("DESC_MAIN").Value; data.Keyword = config.GetConfigById("KEYWORD").Value; data.LinkFace = config.GetConfigById("LINK_FACE").Value; data.LinkedIn = config.GetConfigById("LINK_LINKEDIN").Value; data.LinkYoutube = config.GetConfigById("LINK_YOUTUBE").Value; return(data); }
public MutationTest(DatabaseFixture fixture) { this.fixture = fixture; ILoggerFactory factory = new NullLoggerFactory(); _projectService = new ProjectService(fixture.context); _evaluationService = new EvaluationService(fixture.context); _participantService = new ParticipantService(fixture.context); _questionService = new QuestionService(fixture.context); _answerService = new AnswerService(fixture.context); _actionService = new ActionService(fixture.context); _noteService = new NoteService(fixture.context); _closingRemarkService = new ClosingRemarkService(fixture.context); _questionTemplateService = new QuestionTemplateService(fixture.context); _projectCategoryService = new ProjectCategoryService(fixture.context); _authService = new MockAuthService(); _mutation = new Mutation( _projectService, _evaluationService, _participantService, _questionService, _answerService, _actionService, _noteService, _closingRemarkService, _questionTemplateService, _projectCategoryService, _authService, new Logger <Mutation>(factory) ); _project = _projectService.Create("Project"); }
public void SetUp() { // Create a new mock of the repository answerRepo = new Mock <IUnitOfWork>(); // Set up the mock for the repository answerRepo.Setup(x => x.Answers.GetList()) .Returns(new List <Answer> { new Answer { Id = Guid.NewGuid(), AnswerTitle = "1" }, new Answer { Id = Guid.NewGuid(), AnswerTitle = "2" }, new Answer { Id = Guid.NewGuid(), AnswerTitle = "3" } }); answerRepo.Setup(x => x.Answers.GetById(id)) .Returns(new Answer { Id = id, AnswerTitle = "5" }); answerRepo.Setup(x => x.Answers.Create(It.IsAny <Answer>())).Callback(() => answers.Add(It.IsAny <Answer>())); answerRepo.Setup(x => x.Answers.Update(It.IsAny <Answer>())).Callback(() => answerTest.AnswerTitle = "My name is test"); answerRepo.Setup(x => x.Answers.Delete(It.IsAny <Guid>())).Callback(() => boolDelete = true); // Create the service and inject the repository into the service answerService = new AnswerService(answerRepo.Object); }
public CometClientProcessor() { // Dependency Injection (design pattern ) implementation/realization other class in Constructor this._questionService = new QuestionService(); this._answerService = new AnswerService(); this._gameService = new GameService(); }
public string GetUserHomeWrok() { var a = AnswerService.GetListBySql(1); AnswerService.GetList(1); return(""); }
public void GetAnswersByQuestionId_passNullId_ShouldReturnTrue() { //Arrange int?id = 0; if (id == 0) { id = null; } using var context = new ApplicationDbContext(options); context.Questions.Add(new Question { Id = 100 }); context.Answers.Add(new Answer { QuestionId = 1, Text = "Answer1" }); context.SaveChanges(); var unitOfWork = new EFUnitOfWork(context); //Act AnswerService answerService = new AnswerService(unitOfWork, _mapper, _logger.Object); //Assert Action act = () => answerService.GetAnswersByQuestionId(id); var exception = Assert.Throws <ArgumentNullException>(act); Assert.Equal("Value cannot be null. (Parameter 'id')", exception.Message); }
public void GetAnswersByQuestionId_ShouldReturnTrue() { int questionId = 44; //Arrange using var context = new ApplicationDbContext(options); context.Questions.Add(new Question { Id = questionId }); context.Answers.Add(new Answer { QuestionId = questionId, Text = "Answer1" }); context.Answers.Add(new Answer { QuestionId = questionId, Text = "Answer2" }); context.Answers.Add(new Answer { QuestionId = questionId, Text = "Answer3" }); context.Answers.Add(new Answer { QuestionId = questionId + 1, Text = "Answer4" }); context.SaveChanges(); var unitOfWork = new EFUnitOfWork(context); //Act AnswerService answerService = new AnswerService(unitOfWork, _mapper, _logger.Object); var result = answerService.GetAnswersByQuestionId(questionId); //Assert Assert.Equal(3, result.Count()); }
public AccountController(QuizAppDb context, UserManager <User> userManager, IConfiguration configuration) { _context = context; _answerService = new AnswerService(_context); _userManager = userManager; _configuration = configuration; }
public async Task DeleteAsyncShouldDeleteAnswer() { // Arrange var db = Tests.GetDatabase(); var answer1 = new AnswerOption { Id = 1 }; var answer2 = new AnswerOption { Id = 2 }; var answer3 = new AnswerOption { Id = 3 }; await db.AddRangeAsync(answer1, answer2, answer3); await db.SaveChangesAsync(); var answerService = new AnswerService(db); // Act await answerService.DeleteAsync(2); var result = await db.AnswerOptions.ToListAsync(); // Assert result .Should() .Match(r => r.ElementAt(0).Id == 1 && r.ElementAt(1).Id == 3) .And .HaveCount(2); }
public void ParseTestAnswer_ShouldReplaceWhitespacesToSingleSpace(string userAnswer, string resultAnswer) { var sut = new AnswerService(); var result = sut.ParseTestAnswer(userAnswer); result.Should().Be(resultAnswer); }
public void GetQueryable() { AnswerService answerService = new AnswerService(_context); IQueryable <Answer> answerQueryable = answerService.GetAll(); Assert.True(answerQueryable.Count() > 0); }
private void CreateServices() { QuizService = new QuizService(QuizRepo, QuizRatingRepo); QuestionService = new QuestionService(QuestionRepo); AnswerService = new AnswerService(AnswerRepo); QuizCategoryService = new QuizCategoryService(QuizCategoryRepo); QuizResultService = new QuizResultService(QuizRepo, QuizResultRepo, QuizRatingRepo); }
public IHttpActionResult Get(string uid) { var answerService = new AnswerService(); var result = answerService.DeleteAnswers(uid); var message = $"Number of records updated: {result}"; return(Ok(message)); }
public void oneTimeSetUp() { var connection = DbConnectionFactory.CreateTransient(); this.ctx = new ApplicationDbContext(connection); this.serv = new AnswerService(new AnswerRepository(ctx)); new DatabaseSeeder().CreateDependenciesAndSeed(ctx);//heavy duty }
public void SetUp() { _validator = new Mock <AbstractValidator <AnswerDto> >(); _validator.Setup(validator => validator.ValidateAsync(It.IsAny <ValidationContext <AnswerDto> >(), It.IsAny <CancellationToken>())) .ReturnsAsync(new ValidationResult()); _context = new QuizDbContext(UnitTestsHelper.GetUnitTestDbOptions()); _helper = new Mock <IServiceHelper <Answer> >(); _service = new AnswerService(_context, _helper.Object, _validator.Object); }
public void TestInitialize() { answerRepoMock = new Mock <IEfGenericRepository <Answer> >(); mapperMock = new Mock <IMappingProvider>(); saverMock = new Mock <ISaver>(); randomMock = new Mock <IRandomProvider>(); answerService = new AnswerService(answerRepoMock.Object, mapperMock.Object, saverMock.Object, randomMock.Object); }
public void Validate_survey_results() { QuestionService questionService = new QuestionService(CreateQuestionStubRepository()); AnswerService answerService = new AnswerService(CreateAnswerStubRepository(), questionService); Dictionary <int, List <int> > results = answerService.GetAnswersByQuestion(); Assert.Equal(3, results.Keys.Count); }
public HomeController(QuestionService questionService, UserService userService, AnswerService answerService, ILogger <HomeController> logger) { _questionService = questionService; _userService = userService; _answerService = answerService; _logger = logger; _logger.LogDebug("logger in HomeController:"); }