public void GetQuestion_BadQuestionIdSubmitted_ThrowArgumentException() { //ARRANGE var options = new DbContextOptionsBuilder().UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name).Options; var context = new ApplicationContext(options); var repository = new QuestionRepository(context); //ACT //ASSERT Assert.ThrowsException <ArgumentException>(() => repository.Get(0)); Assert.ThrowsException <ArgumentException>(() => repository.Get(-2)); }
public void Question_UpdateCorrect() { var options = new DbContextOptionsBuilder <QAndAContext>().UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name).Options; var context = new QAndAContext(options); IQuestionRepository QRepo = new QuestionRepository(context); var question = new QuestionTO { Questioning = "Am I a construction vehicule ?", CreationDate = DateTime.Now, State = State.Pending, IsArchived = false, LostSoul = new UserTO { FirstName = "Stan", LastName = "The Cat" } }; var insertedQuestion = QRepo.Insert(question); QRepo.Save(); insertedQuestion.Questioning = "Stupid Question"; var result = QRepo.Update(insertedQuestion); QRepo.Save(); Assert.AreEqual("Stupid Question", QRepo.Get(result.Id).Questioning); }
public void Question_ArchiveSuccesfull() { var options = new DbContextOptionsBuilder <QAndAContext>().UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name).Options; var context = new QAndAContext(options); IQuestionRepository QRepo = new QuestionRepository(context); var question = new QuestionTO { Questioning = "Gif or Gif ?", CreationDate = DateTime.Now, State = State.Pending, IsArchived = false, LostSoul = new UserTO { FirstName = "William", LastName = "Shake" } }; var added = QRepo.Insert(question); QRepo.Save(); var result = QRepo.Archive(added); QRepo.Save(); Assert.IsTrue(QRepo.Get(added.Id).IsArchived); }
public void GetQuestion_AddNewQuestionThenRetrieveAddedQuestion_ReturnAddedQuestionNotNull() { //ARRANGE var options = new DbContextOptionsBuilder().UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name).Options; var context = new ApplicationContext(options); var repository = new QuestionRepository(context); var question = new Question { Message = "Test question", PostDate = DateTime.Now, State = QuestionState.Waiting, IsDeleted = false, Requester = new ApplicationUser { Id = "aaaaabbbbbcccccdddd", Email = "*****@*****.**" } }; var addedQuestion = repository.Insert(question); context.SaveChanges(); //ACT var result = repository.Get(addedQuestion.Id); //ASSERT Assert.IsNotNull(addedQuestion); Assert.AreNotEqual(0, addedQuestion.Id); Assert.IsNotNull(result); Assert.AreEqual("Test question", result.Message); }
public Form1() { InitializeComponent(); editor.Name = "txtAnswer"; editor.Dock = DockStyle.Fill; pnlEditor.Controls.Add(editor); editor.SetupFont(defaultFont, defaultColor, defaultSize); QuestionRepository helper = new QuestionRepository(liteDBPath); filteredQuestions = helper.Get(0, 0, chkActiveOnly.Checked); //chkActiveOnly.Checked = true; dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; RefreshGridView(filteredQuestions); int binIndex = app_directory.IndexOf(@"\bin\"); if (binIndex > -1) { app_directory = app_directory.Substring(0, binIndex + 1); //project directory } }
public QuestionDTO Get(int ID) { QuestionEntity getquestion = ur.Get(ID); QuestionDTO question = Mapper.Map <QuestionDTO>(getquestion); return(question); }
public void Question_Get_NothingToGet() { var options = new DbContextOptionsBuilder <QAndAContext>().UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name).Options; var context = new QAndAContext(options); IQuestionRepository QRepo = new QuestionRepository(context); Assert.ThrowsException <ArgumentException>(() => QRepo.Get(-15)); }
public void GetTest() { var data = repository.Get("538359db10fb8e1248981698"); //Xunit.Assert.NotNull(data); Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsNotNull(data); //Xunit.Assert.True(data.Count() > 0); Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsTrue(data.Body.Equals("Jahirul Islam")); }
public Test Get(int id = default) { try { Test test = new Test(); using (var connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(); connection.Open(); command.Connection = connection; command.CommandText = string.Format("SELECT * FROM KnowledgeBase.dbo.[Test] WHERE Id = {0} ", id); SqlParameter IdParam = new SqlParameter("@IdParam", id); command.Parameters.Add(IdParam); IDataReader dr = command.ExecuteReader(); if (dr.Read()) { test.Id = (int)dr["Id"]; test.Name = dr["Name"].ToString(); test.Duration = (DateTime)dr["Duration"]; test.Questions = qr.Get((int)dr["TestId"]); //Список вопросов return(test); } else { return(null); } } } catch (NullReferenceException) { return(null); } }
protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings) { var nodes = new TreeNodeCollection(); if (id.Equals(this.rootId)) { var questionRespository = new QuestionRepository(); var questions = questionRespository.Get(); foreach (var question in questions) { nodes.Add(this.CreateTreeNode(question.Id.ToString(), id, queryStrings, question.Name, "icon-poll", false)); } } return(nodes); }
public void UpdateAnswer_Correct() { var options = new DbContextOptionsBuilder <QAndAContext>().UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name).Options; var context = new QAndAContext(options); IAnswerRepository ARepo = new AnswerRepository(context); IQuestionRepository QRepo = new QuestionRepository(context); var question = new QuestionTO { Questioning = "Maybe it's working", CreationDate = DateTime.Now, State = State.Pending, IsArchived = false, LostSoul = new UserTO { FirstName = "Call me", LastName = "Kevin" } }; var addedQuestion = QRepo.Insert(question); QRepo.Save(); var answer = new AnswerTO { Answering = "No shit Sherlock", AnswerTime = DateTime.Now.AddHours(1), QuestionId = addedQuestion.Id, Savior = new UserTO { FirstName = "Dr", LastName = "Watson" } }; var addedAnswer = ARepo.Insert(answer); ARepo.Save(); addedAnswer.Answering = "Can't be right"; var updatedAnswer = ARepo.Update(addedAnswer); ARepo.Save(); Assert.AreEqual(1, ARepo.GetAll().Count()); Assert.AreEqual(1, QRepo.Get(addedAnswer.QuestionId).Answers.Count()); Assert.AreEqual("Can't be right", ARepo.Get(updatedAnswer.Id).Answering); }
private void FilterGridView() { var QuestionHelper = new QuestionRepository(liteDBPath); int num1, num2; if (!Int32.TryParse(this.txtFrom.Text, out num1)) { num1 = 0; } if (!Int32.TryParse(this.txtTo.Text, out num2)) { num2 = 0; } IList <Question> items = QuestionHelper.Get(num1, num2, chkActiveOnly.Checked); filteredQuestions = items; RefreshGridView(items); }
public HttpResponseMessage DeleteQuestion(int id) { Question question = QuestionRepository.Get(t => t.QuestionId == id); if (question == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } QuestionRepository.Delete(question); try { unitOfWork.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex)); } return(Request.CreateResponse(HttpStatusCode.OK, question)); }
public void Get_Question_Not_Found_Error() { BitcoinShowDBContext context = DbContextFactory.GetContext(); for (int i = 0; i < 10; i++) { context.Questions.Add(new Question { Title = $"Random Question {i + 1}", Answer = new Option { Id = i, Text = $"Random Option {i}" } }); } context.SaveChanges(); QuestionRepository repository = new QuestionRepository(context); Question actual = repository.Get(50); Assert.Null(actual); }
public void Question_Get() { var options = new DbContextOptionsBuilder <QAndAContext>().UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name).Options; var context = new QAndAContext(options); IQuestionRepository QRepo = new QuestionRepository(context); var question = new QuestionTO { Questioning = "How can i make money with that ?", CreationDate = DateTime.Now, State = State.Resolved, IsArchived = false, LostSoul = new UserTO { FirstName = "Captain", LastName = "Krabs" } }; var added = QRepo.Insert(question); QRepo.Save(); var result = QRepo.Get(added.Id); Assert.AreEqual("How can i make money with that ?", result.Questioning); }
public void Get_Question_Success() { BitcoinShowDBContext context = DbContextFactory.GetContext(); for (int i = 0; i < 98; i++) { context.Questions.Add(new Question { Title = $"Random Question {i + 1}", Answer = new Option { Id = i, Text = $"Random Option {i}" }, Level = LevelEnum.VeryHard }); } context.SaveChanges(); QuestionRepository repository = new QuestionRepository(context); Question actual = repository.Get(50); Assert.NotNull(actual); Assert.NotNull(actual.Answer); }
public async Task QuestionTableShouldBeCreatedSuccessfullyTest() { var questions = await _questionRespository.Get(); Assert.False(questions.Any()); }
public Question Get(Guid id) { return(_repository.Get(id)); }
public IActionResult Get() { return(Ok(_questionRepository.Get().Select(QuestionViewModel.ToViewModel))); }
public Question Get(int id) { var question = QuestionRepository.Get(id); return(question); }
public List <Questions> Get() { return(repo.Get()); }
/// <summary> /// 回答新闻的互动问题 /// </summary> /// <returns></returns> public static Result <int> Add(QuestionFeedbackModel ent) { var result = new Result <int>(); if (ent.UserId <= 0 || ent.NewsId <= 0) { result.Message = "无效的参数"; return(result); } if (ent.QuestionOption.IsNullOrEmpty()) { result.Message = "提交的互动问题不能为空"; return(result); } var feedback = ent.QuestionOption.JsonDeserialize <List <QuestionOptionRequest> >(); if (feedback.IsNullOrEmpty()) { result.Message = "提交的互动问题无效"; return(result); } if (QuestionFeedbackRepository.Exists(ent.NewsId, ent.UserId)) { result.Message = "请勿重复提交问卷"; return(result); } var memberInfo = MemberRepository.Get(ent.UserId); if (memberInfo == null) { result.Message = "会员信息无效"; return(result); } decimal score = 0; feedback.ForEach(item => { var questionInfo = QuestionRepository.Get(item.QId); if (questionInfo != null) { ent.QuestionId = item.QId; ent.QuestionOption = item.Text; var iRet = QuestionFeedbackRepository.Add(ent); if (iRet > 0) { score += questionInfo.QuestionScore; result.Code = ResultCode.Success; } } }); //修改用户积分 memberInfo.TotalScore += score; MemberRepository.Update(memberInfo); //增加账户明细 FundingRepository.Add(new MemberFundingModel() { UserId = ent.UserId, OpType = OperationType.QuestionFeedback, ChangeType = ScoreChangeType.Increase, OpValue = score, Remark = OperationType.QuestionFeedback.Description(), CreateTime = DateTime.Now }); return(result); }
public Question Get(int id) { return(QuestionRepository.Get(t => t.QuestionId == id)); }
public Question Get(int id) { var question = QuestionRepository.Get(id); if (question != null) { if (question.QuestionTypeId == 10) // MovePointsInAChart { var mpic = new MovePointsInAChart(question); var details = Serializer.Deserialize <MovePointsInAChart_QuestionXmlModel>(mpic.ExtendedDetails); mpic.Domain = details.Domain; mpic.MinorScale = details.MinorScale; mpic.MajorScale = details.MajorScale; mpic.chartType = details.chartType; foreach (var answer in mpic.Answers) { var answerDetails = Serializer.Deserialize <MovePointsInAChart_SpotXmlModel>(answer.ExendedDetails); if (answerDetails.SpotType == "center") { mpic.CenterSpot = new SpotContent { X = answerDetails.X, Y = answerDetails.Y }; } else { mpic.MinMaxSpot = new SpotContent { X = answerDetails.X, Y = answerDetails.Y }; } } return(mpic); } else if (question.QuestionTypeId == 20) // MovePointsInALine { var mpil = new MovePointsInALine(question); var details = Serializer.Deserialize <MovePointsInALine_QuestionXmlModel>(mpil.ExtendedDetails); mpil.MinValue = details.MinValue; mpil.MaxValue = details.MaxValue; mpil.MinorScale = details.MinorScale; mpil.MajorScale = details.MajorScale; var intervalsBuffer = new List <MovePointsInALine_Interval>(); foreach (var answer in mpil.Answers) { var answerDetails = Serializer.Deserialize <MovePointsInALine_IntervalXmlModel>(answer.ExendedDetails); intervalsBuffer.Add(new MovePointsInALine_Interval { id = answerDetails.Id, minValue = answerDetails.MinValue, maxValue = answerDetails.MaxValue, minValueType = answerDetails.MinValueType, maxValueType = answerDetails.MaxValueType, shapeType = answerDetails.ShapeType, value = answerDetails.Value, label = answerDetails.Label }); } mpil.Intervals = intervalsBuffer.ToArray(); return(mpil); } else if (question.QuestionTypeId == 30) // SelectableChart { var sc = new SelectableChart(question); var columnsBuffer = new List <SelectableChart_Column>(); foreach (var answer in sc.Answers) { var answerDetails = Serializer.Deserialize <SelectableChart_ColumnXmlModel>(answer.ExendedDetails); columnsBuffer.Add(new SelectableChart_Column { id = answerDetails.Id, label = answerDetails.Label, selected = answerDetails.Selected, value = answerDetails.Value }); } sc.Columns = columnsBuffer.ToArray(); return(sc); } else if (question.QuestionTypeId == 40) // DragAndDrop { var mdd = new MultipleDragAndDrop(question); var details = Serializer.Deserialize <MultipleDragAndDrop_QuestionXmlModel>(mdd.ExtendedDetails); mdd.AnswersList = details.Answers.Select(x => new MultipleDragAndDrop_Answer() { id = x.Id, text = x.Text, DisplayAnswersVertically = x.DisplayAnswersVertically }).ToArray(); var targetsBuffer = new List <MultipleDragAndDrop_Target>(); foreach (var answer in mdd.Answers) { var answerDetails = Serializer.Deserialize <MultipleDragAndDrop_TargetXmlModel>(answer.ExendedDetails); targetsBuffer.Add(new MultipleDragAndDrop_Target { id = answerDetails.Id, text = answerDetails.Text, answerId = answerDetails.AnswerId, answerText = answerDetails.AnswerText }); } mdd.Targets = targetsBuffer.ToArray(); return(mdd); } else if (question.QuestionTypeId == 50) // Drag And order { var dao = new DragAndOrder(question); var optionsBuffer = new List <DragAndOrder_Option>(); foreach (var answer in dao.Answers) { var answerDetails = Serializer.Deserialize <DragAndOrder_OptionXmlModel>(answer.ExendedDetails); optionsBuffer.Add(new DragAndOrder_Option { id = answerDetails.Id, text = answerDetails.Text, worth = answerDetails.Worth }); } dao.Options = optionsBuffer.ToArray(); return(dao); } else if (question.QuestionTypeId == 42) // MultipleDragAndDropImage { var mddi = new MultipleDragAndDropImage(question); var AnswersList = new List <MultipleDragAndDropImage_Answer>(); foreach (var answer in mddi.Answers) { AnswersList.Add(new MultipleDragAndDropImage_Answer { imgName = answer.Txt, imgData = null, imgURL = answer.ExendedDetails, isCorrect = answer.AnsVal, }); } mddi.AnswersList = AnswersList.ToArray(); return(mddi); } else if (question.QuestionTypeId == 44) // MultipleDragAndDropJustification { var mdd = new MultipleDragAndDropJustification(question); // method and justification questions var details = Serializer.Deserialize <MultipleDragAndDrop_JustificationQuestionXmlModel>(mdd.ExtendedDetails); mdd.AnswersList = details.Answers.Select(x => new MultipleDragAndDrop_Answer() { id = x.Id, text = x.Text, }).ToArray(); mdd.JustificationAnswersList = details.JustificationAnswers.Select(x => new MultipleDragAndDrop_JustificationAnswer() { id = x.Id, text = x.Text, }).ToArray(); // method and justification responses var targetsBuffer = new List <MultipleDragAndDrop_Target>(); var targetsBufferj = new List <MultipleDragAndDrop_JustificationTarget>(); foreach (var answer in mdd.Answers) { if (answer.ExendedDetails.IndexOf("MultipleDragAndDrop_TargetXmlModel") >= 0) { //method responses var answerDetails = Serializer.Deserialize <MultipleDragAndDrop_TargetXmlModel>(answer.ExendedDetails); targetsBuffer.Add(new MultipleDragAndDrop_Target { id = answerDetails.Id, text = answerDetails.Text, answerId = answerDetails.AnswerId, answerText = answerDetails.AnswerText }); } else if (answer.ExendedDetails.IndexOf("MultipleDragAndDrop_JustificationTargetXmlModel") >= 0) { //justification responses var answerDetails = Serializer.Deserialize <MultipleDragAndDrop_JustificationTargetXmlModel>(answer.ExendedDetails); targetsBufferj.Add(new MultipleDragAndDrop_JustificationTarget { id = answerDetails.Id, text = answerDetails.Text, answerId = answerDetails.AnswerId, answerText = answerDetails.AnswerText }); } } mdd.Targets = targetsBuffer.ToArray(); mdd.JustificationTargets = targetsBufferj.ToArray(); return(mdd); } else if (question.QuestionTypeId == 12) // DrawLinesInAChart { var dlc = new DrawLinesInAChart(question); // chart details var chartDetails = Serializer.Deserialize <DrawLinesInAChart_QuestionXmlModel>(dlc.ExtendedDetails); dlc.Domain = chartDetails.Domain; dlc.MajorScale = chartDetails.MajorScale; dlc.MinorScale = chartDetails.MinorScale; // line details var AnswersList = new List <DrawLinesInAChartAnswer>(); foreach (var answer in dlc.Answers) { var answerDetails = Serializer.Deserialize <DrawLinesInAChart_AnswerXmlModel>(answer.ExendedDetails); AnswersList.Add(new DrawLinesInAChartAnswer { axisValue = answerDetails.axisValue, axisType = answerDetails.axisType, }); } dlc.AnswersList = AnswersList.ToArray(); return(dlc); } else if (question.QuestionTypeId == 46) // MultipleDragAndDropExpression { var mdde = new MultipleDragAndDropExpression(question); var details = Serializer.Deserialize <MultipleDragAndDropExpression_QuestionXmlModel>(mdde.ExtendedDetails); mdde.AnswersList = details.Answers.Select(x => new MultipleDragAndDropExpression_Answer() { id = x.Id, text = x.Text, }).ToArray(); var targetsBuffer = new List <MultipleDragAndDropExpression_Target>(); foreach (var answer in mdde.Answers) { var answerDetails = Serializer.Deserialize <MultipleDragAndDropExpression_TargetXmlModel>(answer.ExendedDetails); targetsBuffer.Add(new MultipleDragAndDropExpression_Target { id = answerDetails.Id, text = answerDetails.Text, answerId = answerDetails.AnswerId, answerText = answerDetails.AnswerText, shape = answerDetails.Shape, container = answerDetails.Container, containerLabel = answerDetails.ContainerLabel, containerBorder = answerDetails.ContainerBorder, containerPosition = answerDetails.ContainerPosition }); } mdde.Targets = targetsBuffer.ToArray(); return(mdde); } else if (question.QuestionTypeId == 48) // MultipleDragAndDrop { var mdd = new MultipleDragAndDrop2(question); // get the options var details = Serializer.Deserialize <MultipleDragAndDrop2_QuestionXmlModel>(mdd.ExtendedDetails); mdd.AnswersList = details.Answers.Select(x => new MultipleDragAndDrop2_Answer() { id = x.Id, text = x.Text, DisplayAnswersVertically = x.DisplayAnswersVertically }).ToArray(); var targetsBuffer = new List <MultipleDragAndDrop2_Target>(); // get the answers foreach (var answer in mdd.Answers) { var answerDetails = Serializer.Deserialize <MultipleDragAndDrop2_TargetXmlModel>(answer.ExendedDetails); targetsBuffer.Add(new MultipleDragAndDrop2_Target { id = answerDetails.Id, text = answerDetails.Text, }); // add the possible options to the answer for (int i = 0; i < targetsBuffer.Count; i++) { if (targetsBuffer[i].id == answerDetails.Id) { targetsBuffer[i].Answers = answerDetails.Answers.Select(x => new MultipleDragAndDrop2_TargetAnswer() { AnswerId = x.AnswerId, AnswerText = x.AnswerText }).ToArray(); } } } mdd.Targets = targetsBuffer.ToArray(); return(mdd); } // else if = 48 (Multiple Drag and Drop) } return(question); } // end Get