public void GetSurveyByTenantAndSlugNameReturnsWithQuestionPossibleAnswers() { string expectedKey = string.Format(CultureInfo.InvariantCulture, "{0}_{1}", "tenant", "slug-name"); var surveyRow = new SurveyRow { RowKey = expectedKey }; var surveyRowsForTheQuery = new[] { surveyRow }; var mockSurveyTable = new Mock <IAzureTable <SurveyRow> >(); mockSurveyTable.SetupGet(t => t.Query).Returns(surveyRowsForTheQuery.AsQueryable()); mockSurveyTable.Setup(t => t.GetRetryPolicyFactoryInstance()).Returns(new DefaultRetryPolicyFactory()); var questionRow = new QuestionRow { PartitionKey = expectedKey, PossibleAnswers = "possible answers", Type = Enum.GetName(typeof(QuestionType), QuestionType.SimpleText) }; var questionsForTheQuery = new[] { questionRow }; var mockQuestionTable = new Mock <IAzureTable <QuestionRow> >(); mockQuestionTable.SetupGet(t => t.Query).Returns(questionsForTheQuery.AsQueryable()); mockQuestionTable.Setup(t => t.GetRetryPolicyFactoryInstance()).Returns(new DefaultRetryPolicyFactory()); var store = new SurveyStore(mockSurveyTable.Object, mockQuestionTable.Object, null); var survey = store.GetSurveyByTenantAndSlugName("tenant", "slug-name", true); Assert.AreEqual("possible answers", survey.Questions.First().PossibleAnswers); }
public async Task DeleteSurveyByTenantAndSlugNameDeleteQuestionsByTenantAndSlugNameInPartitionKeyFromQuestionTable() { string expectedKey = string.Format(CultureInfo.InvariantCulture, "{0}_{1}", "tenant", "slug-name"); var surveyRow = new SurveyRow { RowKey = expectedKey }; var mockSurveyTable = new Mock <IAzureTable <SurveyRow> >(); mockSurveyTable.Setup(t => t.GetByRowKeyAsync(expectedKey)).ReturnsAsync(new[] { surveyRow }); var questionRow = new QuestionRow { PartitionKey = expectedKey, PossibleAnswers = "possible answers", Type = Enum.GetName(typeof(QuestionType), QuestionType.SimpleText) }; var questions = new[] { questionRow }; var mockQuestionTable = new Mock <IAzureTable <QuestionRow> >(); mockQuestionTable.Setup(t => t.GetByPartitionKeyAsync(expectedKey)).ReturnsAsync(questions); IEnumerable <QuestionRow> actualQuestionsToDelete = null; mockQuestionTable.Setup(t => t.DeleteAsync(It.IsAny <IEnumerable <QuestionRow> >())) .Returns(Task.Delay(0)) .Callback <IEnumerable <QuestionRow> >(q => actualQuestionsToDelete = q); var store = new SurveyStore(mockSurveyTable.Object, mockQuestionTable.Object, new Mock <IInitializationStatusService>().Object); await store.DeleteSurveyByTenantAndSlugNameAsync("tenant", "slug-name"); Assert.AreEqual(1, actualQuestionsToDelete.Count()); Assert.AreSame(questionRow, actualQuestionsToDelete.First()); }
public void DeleteSurveyByTenantAndSlugNameDeleteQuestionsByTenantAndSlugNameInPartitionKeyFromQuestionTable() { string expectedKey = string.Format(CultureInfo.InvariantCulture, "{0}_{1}", "tenant", "slug-name"); var surveyRow = new SurveyRow { RowKey = expectedKey }; var otherSurveyRow = new SurveyRow { RowKey = "other_row_key" }; var surveyRowsForTheQuery = new[] { surveyRow, otherSurveyRow }; var mockSurveyTable = new Mock <IAzureTable <SurveyRow> >(); mockSurveyTable.SetupGet(t => t.Query).Returns(surveyRowsForTheQuery.AsQueryable()); mockSurveyTable.Setup(t => t.GetRetryPolicyFactoryInstance()).Returns(new DefaultRetryPolicyFactory()); var questionRow = new QuestionRow { PartitionKey = expectedKey, PossibleAnswers = "possible answers", Type = Enum.GetName(typeof(QuestionType), QuestionType.SimpleText) }; var questionsForTheQuery = new[] { questionRow }; var mockQuestionTable = new Mock <IAzureTable <QuestionRow> >(); mockQuestionTable.SetupGet(t => t.Query).Returns(questionsForTheQuery.AsQueryable()); mockQuestionTable.Setup(t => t.GetRetryPolicyFactoryInstance()).Returns(new DefaultRetryPolicyFactory()); IEnumerable <QuestionRow> actualQuestionsToDelete = null; mockQuestionTable.Setup(t => t.Delete(It.IsAny <IEnumerable <QuestionRow> >())) .Callback <IEnumerable <QuestionRow> >(q => actualQuestionsToDelete = q); var store = new SurveyStore(mockSurveyTable.Object, mockQuestionTable.Object, null); store.DeleteSurveyByTenantAndSlugName("tenant", "slug-name"); Assert.AreEqual(1, actualQuestionsToDelete.Count()); Assert.AreSame(questionRow, actualQuestionsToDelete.First()); }
public QuestionRow AddQuestionRow(string QuestionText, VoterRow parentVoterRowByVoterQuestion) { QuestionRow rowQuestionRow = ((QuestionRow)(this.NewRow())); rowQuestionRow.ItemArray = new object[] { QuestionText, parentVoterRowByVoterQuestion[0], null }; this.Rows.Add(rowQuestionRow); return(rowQuestionRow); }
/// <summary> /// Generates an exam and returns the exam /// </summary> /// <returns></returns> GameObject GenerateExam() { // empty parent object for positioning purposes (also contains a broken checkbox header, remove those and attach separately) GameObject exam = (GameObject)Instantiate(examPrefab, desk.transform.position + Vector3.up * /*(desk.transform.GetComponent<Collider>().bounds.extents.y + 0.01f)*/ 0.022f, Quaternion.identity); //new Vector3(0, desk.transform.localScale.z / 2, 0), Quaternion.identity); //load a bunch of random words from a text file and split on newline string[] questions = questionFile.text.Split('\n'); // iterate through the number of questions wanted, layout optimized for 5 for (int i = 0; i < questionAmount; i++) { // row object, contains three checkboxes and a question text field GameObject row = (GameObject)Instantiate(rowPrefab, exam.transform.position + Vector3.forward * (questionAmount / 2) * 0.0001f + Vector3.back * i * 0.15f, Quaternion.identity); // make up a question string question = ""; for (int j = 0; j < UnityEngine.Random.Range(4, 6); j++) // 4-5 random words, 7 was too much with current words { question += (question.Length == 0 ? "-" : " ") + questions[UnityEngine.Random.Range(0, questions.Length - 1)]; } question += "?"; // append a question mark for good measure row.transform.FindChild("Question").GetComponent <Text>().text = question; // set the text for the object // randomize which checkbox is correct TODO mark the correct answers on neighbour exams QuestionRow questionrow = row.GetComponent <QuestionRow>(); for (int j = 0; j < row.transform.GetComponentsInChildren <BoxCollider>().Length; j++) { checkboxes.Add(row.transform.GetComponentsInChildren <BoxCollider>()[j].gameObject); } questionrow.rightAnswerBox = row.transform.GetComponentsInChildren <BoxCollider>()[UnityEngine.Random.Range(0, 3)].gameObject; correctCheckboxes.Add(questionrow.rightAnswerBox); checkboxes.Remove(questionrow.rightAnswerBox); row.transform.parent = exam.transform; } wrongAnswers = checkboxes.Count; // Generate copies of exam with correct answers marked on neighboring desks for (int i = 0; i < neighborDesks.Count; i++) { GameObject neighborExam = (GameObject)Instantiate(exam, neighborDesks[i].transform.position + Vector3.up * 0.025f, Quaternion.identity); neighborExam.transform.parent = neighborCanvas[i].transform; for (int j = 0; j < correctCheckboxes.Count; j++) { GameObject correctAnswer = (GameObject)Instantiate(crossMark, new Vector3(neighborDesks[i].transform.position.x, 0, 0) + correctCheckboxes[j].transform.position + Vector3.up * 0.001f, Quaternion.identity); } } exam.transform.parent = canvas.transform; return(exam); }
public async Task GetSurveyByTenantAndSlugNameReturnsWithQuestionPossibleAnswers() { string expectedKey = string.Format(CultureInfo.InvariantCulture, "{0}_{1}", "tenant", "slug-name"); var surveyRow = new SurveyRow { RowKey = expectedKey }; var mockSurveyTable = new Mock <IAzureTable <SurveyRow> >(); mockSurveyTable.Setup(t => t.GetByRowKeyAsync(expectedKey)).ReturnsAsync(new[] { surveyRow }); var questionRow = new QuestionRow { PartitionKey = expectedKey, PossibleAnswers = "possible answers", Type = Enum.GetName(typeof(QuestionType), QuestionType.SimpleText) }; var questions = new[] { questionRow }; var mockQuestionTable = new Mock <IAzureTable <QuestionRow> >(); mockQuestionTable.Setup(t => t.GetByPartitionKeyAsync(expectedKey)).ReturnsAsync(questions); var store = new SurveyStore(mockSurveyTable.Object, mockQuestionTable.Object, new Mock <IInitializationStatusService>().Object); var survey = await store.GetSurveyByTenantAndSlugNameAsync("tenant", "slug-name", true); Assert.AreEqual("possible answers", survey.Questions.First().PossibleAnswers); }
public async Task GetSurveyByTenantAndSlugNameReturnsWithQuestionsFilteredByTenantAndSlugNameInPartitionKey() { string expectedKey = string.Format(CultureInfo.InvariantCulture, "{0}_{1}", "tenant", "slug-name"); var surveyRow = new SurveyRow { RowKey = expectedKey }; var mockSurveyTable = new Mock <IAzureTable <SurveyRow> >(); mockSurveyTable.Setup(t => t.GetByRowKeyAsync(expectedKey)).ReturnsAsync(new[] { surveyRow }); var questionRow = new QuestionRow { PartitionKey = expectedKey, Type = Enum.GetName(typeof(QuestionType), QuestionType.SimpleText) }; var questions = new[] { questionRow }; var mockQuestionTable = new Mock <IAzureTable <QuestionRow> >(); mockQuestionTable.Setup(t => t.GetByPartitionKeyAsync(expectedKey)).ReturnsAsync(questions); var store = new SurveyStore(mockSurveyTable.Object, mockQuestionTable.Object, null); var survey = await store.GetSurveyByTenantAndSlugNameAsync("tenant", "slug-name", true); Assert.AreEqual(1, survey.Questions.Count); }
public void RemoveQuestionRow(QuestionRow row) { this.Rows.Remove(row); }
public void AddQuestionRow(QuestionRow row) { this.Rows.Add(row); }
public QuestionRowChangeEvent(QuestionRow row, DataRowAction action) { this.eventRow = row; this.eventAction = action; }
public async Task SaveSurveyAsync(Survey survey) { if (string.IsNullOrEmpty(survey.SlugName) && string.IsNullOrEmpty(survey.Title)) { throw new ArgumentNullException("survey", "The survey for saving has to have the slug or the title."); } var slugName = string.IsNullOrEmpty(survey.SlugName) ? GenerateSlug(survey.Title, 100) : survey.SlugName; var surveyRow = new SurveyRow { SlugName = slugName, Title = survey.Title, CreatedOn = DateTime.UtcNow, PartitionKey = survey.TenantId }; surveyRow.RowKey = string.Format(CultureInfo.InvariantCulture, "{0}_{1}", survey.TenantId, surveyRow.SlugName); var questionRows = new List <QuestionRow>(survey.Questions.Count); for (int i = 0; i < survey.Questions.Count; i++) { var question = survey.Questions[i]; var questionRow = new QuestionRow { Text = question.Text, Type = Enum.GetName(typeof(QuestionType), question.Type), PossibleAnswers = question.PossibleAnswers }; questionRow.PartitionKey = surveyRow.RowKey; questionRow.RowKey = string.Format(CultureInfo.InvariantCulture, "{0}_{1}", DateTime.UtcNow.GetFormatedTicks(), i.ToString("D3")); questionRows.Add(questionRow); } //// First add the questions await this.questionTable.AddAsync(questionRows); try { //// Then add the survey //// If this fails, the questions may end up orphan but data will be consistent for the user await this.surveyTable.AddAsync(surveyRow); if (this.CacheEnabled) { await TenantCacheHelper.AddToCacheAsync(survey.TenantId, slugName, survey).ConfigureAwait(false); } } //TODO: update this catch for Azure Table client SDK catch (DataServiceRequestException ex) { TraceHelper.TraceError(ex.TraceInformation()); var dataServiceClientException = ex.InnerException as DataServiceClientException; if (dataServiceClientException != null) { if (dataServiceClientException.StatusCode == 409) { await this.questionTable.DeleteAsync(questionRows); throw; } } throw; } }
public void SaveSurvey(Survey survey) { if (string.IsNullOrEmpty(survey.SlugName) && string.IsNullOrEmpty(survey.Title)) { throw new ArgumentNullException("survey", "The survey for saving has to have the slug or the title."); } var slugName = string.IsNullOrEmpty(survey.SlugName) ? GenerateSlug(survey.Title, 100) : survey.SlugName; var surveyRow = new SurveyRow { SlugName = slugName, Title = survey.Title, CreatedOn = DateTime.UtcNow, PartitionKey = survey.Tenant, UserDefinedFields = survey.UserDefinedFields }; surveyRow.RowKey = string.Format(CultureInfo.InvariantCulture, "{0}_{1}", survey.Tenant, surveyRow.SlugName); var questionRows = new List <QuestionRow>(survey.Questions.Count); for (int i = 0; i < survey.Questions.Count; i++) { var question = survey.Questions[i]; var questionRow = new QuestionRow { Text = question.Text, Type = Enum.GetName(typeof(QuestionType), question.Type), PossibleAnswers = question.PossibleAnswers }; questionRow.PartitionKey = surveyRow.RowKey; questionRow.RowKey = string.Format(CultureInfo.InvariantCulture, "{0}_{1}", DateTime.UtcNow.GetFormatedTicks(), i.ToString("D3")); questionRows.Add(questionRow); } //// First add the questions this.questionTable.Add(questionRows); try { //// Then create the container for the answers this.surveyAnswerContainerFactory.Create(surveyRow.PartitionKey, surveyRow.SlugName).EnsureExist(); //// And finally, add the survey //// If this fails, the questions may end up orphan but data will be consistent for the user this.surveyTable.Add(surveyRow); if (this.CacheEnabled) { TenantCacheHelper.AddToCache(survey.Tenant, slugName, survey); } } catch (DataServiceRequestException ex) { TraceHelper.TraceError(ex.TraceInformation()); var dataServiceClientException = ex.InnerException as DataServiceClientException; if (dataServiceClientException != null) { if (dataServiceClientException.StatusCode == 409) { this.questionTable.Delete(questionRows); throw; } } throw; } }
/// <summary> /// กำหนดคำถาม /// </summary> /// <param name="question">คำถาม</param> /// <param name="cupStyleName">ชนิดรูปทรงของแก้ว</param> /// <param name="cupLevel">ชนิดระดับความยากของแก้ว</param> public void SetQuestionRow(QuestionRow question, string cupStyleName, string cupLevel) { if (_lastClickedCup != null) _lastClickedCup.StopCupIncorrect(); _lastClickedCup = null; _cupStyleName = cupStyleName; _cupLevel = cupLevel; _question = question; Storyboard1.SpeedRatio = question.SwapSpeed; Storyboard2.SpeedRatio = question.SwapSpeed; // กำหนด state เริ่มต้นจากจำนวนแก้ว const int VeryEasy = 2; const int Easy = 3; const int Normal = 4; const int Hard = 5; switch (question.CupCount) { case VeryEasy: _cupRowState = "twoCup"; break; case Easy: _cupRowState = "threeCup"; break; case Normal: _cupRowState = "fourCup"; break; case Hard: _cupRowState = "fiveCup"; break; default: break; } // กำหนดการใช้งานของ state manager เพื่อกำหนดการแสดงผลของแก้วที่จะนำไปใช้งาน VisualStateManager.GoToState(this, _cupRowState, false); // เคลียแก้ว foreach (var canvas in _cupCanvases) (canvas.Children[ElementCupIndex] as CupUI).ResetState(); // กำหนดลายแก้ว และวัตถุภายในแก้ว for (int canvasIndex = 0; canvasIndex < _cupCanvases.Count(); canvasIndex++) { if (canvasIndex < question.BeforeCup.Count) { // กำหนดข้อมูลของแก้วที่นำไปแสดงผล (_cupCanvases[canvasIndex].Children[ElementCupIndex] as CupUI) .Initialize(_question.BeforeCup[canvasIndex], getCupStyleName()); } else { // กำหนดวัตถุที่ไม่ได้ถูกนำมาแสดงผลให้ไม่สามารถเปิดแก้วได้ (_cupCanvases[canvasIndex].Children[ElementCupIndex] as CupUI).HasOpened = true; } } // ทำการเปิดแสดงวัตถุที่อยู่ภายในแก้ว foreach (var canvas in _cupCanvases) (canvas.Children[ElementCupIndex] as CupUI).Sb_ShowItem.Begin(); }
public QuestionRowChangeEvent(QuestionRow row, global::System.Data.DataRowAction action) { this.eventRow = row; this.eventAction = action; }