예제 #1
0
        public void Method_DCEventHandler()
        {
            // arrange
            string id        = "keyDCEventHandler";
            bool   isAnswer  = default(bool);
            string name      = "name";
            var    argValues = new Dictionary <int, object>()
            {
                { 0, "value1" }, { 1, "value2" }
            };

            Core.LogChange += CQG_LogChange_Mock;
            var answerHelper = new AnswerHelper();

            UnitTestHelper.StartUp();
            Task.Run(async() =>
            {
                await answerHelper.ClearAnswersListAsync();
            }).GetAwaiter().GetResult();

            // act
            Task.Run(async() =>
            {
                await AnswerHandler.PushAnswerAsync(new AnswerInfo(id, string.Empty, name, null, argValues));
            }).GetAwaiter().GetResult();
            var answer = answerHelper.GetAnswerData(id, out isAnswer);

            // assert
            Assert.IsTrue(isAnswer);
            Assert.AreEqual(id, answer.AnswerKey);
            Assert.IsNotNull(answer.ArgValues);
            Assert.AreEqual("value1", answer.ArgValues[0]);
            Assert.AreEqual("value2", answer.ArgValues[1]);
        }
        public ExamAnswer GetExamAnswer(RequestGetExamAnswer request)
        {
            ExamAnswerHelper eah = new ExamAnswerHelper();
            ExamAnswer       ea  = eah.GetRow(request.usercode, request.ExamPaper);

            AnswerHelper ah = new AnswerHelper();

            ea.Answers = ah.GetRows(ea.GUID);

            AnswerItemHelper aih = new AnswerItemHelper();
            var ais = aih.GetRows(ea.GUID);

            Dictionary <string, IList <AnswerItem> > items = new Dictionary <string, IList <AnswerItem> >();

            foreach (var ai in ais)
            {
                if (!items.ContainsKey(ai.Code))
                {
                    items.Add(ai.Code, new List <AnswerItem>());
                }
                items[ai.Code].Add(ai);
            }

            foreach (var a in ea.Answers)
            {
                a.Answers = items[a.Code];
            }

            return(ea);
        }
예제 #3
0
        public void Method_GetAnswerData()
        {
            // arrange
            AnswerInfo answer   = default(AnswerInfo);
            string     id       = "key";
            bool       isAnswer = default(bool);
            string     name     = "name";

            Core.LogChange += CQG_LogChange_Mock;
            var answerHelper = new AnswerHelper();

            UnitTestHelper.StartUp();
            Task.Run(async() =>
            {
                await answerHelper.ClearAnswersListAsync();
            }).GetAwaiter().GetResult();

            // act
            Task.Run(async() =>
            {
                await AnswerHandler.PushAnswerAsync(new AnswerInfo(id, string.Empty, name));
                answer = answerHelper.GetAnswerData(id, out isAnswer);
            }).GetAwaiter().GetResult();

            // assert
            Assert.IsTrue(isAnswer);
            Assert.AreEqual(id, answer.AnswerKey);
        }
예제 #4
0
        public void MethodAsync_RemoveOneAnswerItem()
        {
            // arrange
            string id       = "key";
            bool   isAnswer = default(bool);
            string name     = "name";

            Core.LogChange += CQG_LogChange_Mock;
            var answerHelper = new AnswerHelper();

            UnitTestHelper.StartUp();
            Task.Run(async() =>
            {
                await answerHelper.ClearAnswersListAsync();
            }).GetAwaiter().GetResult();

            Task.Run(async() =>
            {
                // act
                await AnswerHandler.PushAnswerAsync(new AnswerInfo(id, string.Empty, name, null, null));
                isAnswer = await answerHelper.CheckAnswerAsync(id);
                await answerHelper.RemoveAnswerAsync(id);
                isAnswer = await answerHelper.CheckAnswerAsync(id);
            }).GetAwaiter().GetResult();

            // assert
            Assert.AreEqual(isAnswer, false);
        }
예제 #5
0
        public void MethodAsync_PushOneAnswerItem()
        {
            // arrange
            string idTrue   = "keyTrue";
            string idFalse  = "keyFalse";
            string name     = "name";
            bool   isAnswer = default(bool);

            Core.LogChange += CQG_LogChange_Mock;
            var answerHelper = new AnswerHelper();

            Task.Run(async() =>
            {
                await answerHelper.ClearAnswersListAsync();
            }).GetAwaiter().GetResult();
            Task.Run(async() =>
            {
                // act 1
                await AnswerHandler.PushAnswerAsync(new AnswerInfo(idTrue, string.Empty, name, null, null));
                isAnswer = await answerHelper.CheckAnswerAsync(idTrue);

                // assert 1
                Assert.AreEqual(isAnswer, true);

                // act 2
                isAnswer = await answerHelper.CheckAnswerAsync(idFalse);

                // assert 2
                Assert.AreEqual(isAnswer, false);
            }).GetAwaiter().GetResult();
        }
예제 #6
0
        public ActionResult Status(int?p)
        {
            this.InitIntPage(ref p);
            var Ld = AnswerHelper.Status(DB, p.Value);

            ViewData["source"] = Ld;
            DB.Dispose();
            return(View());
        }
        public async Task <OperationResult> DeleteAnswerByMicrotingUid(int microtingUid)
        {
            try
            {
                var core = await _coreHelper.GetCore();

                using (var sdkContext = core.DbContextHelper.GetDbContext())
                {
                    var answer = await AnswerHelper.GetAnswerQueryByMicrotingUidForDelete(microtingUid, sdkContext)
                                 .FirstOrDefaultAsync();

                    if (answer == null)
                    {
                        return(new OperationResult(
                                   false,
                                   _localizationService.GetString("AnswerNotFound")));
                    }

                    var answersValues = await AnswerHelper.GetAnswerValuesQueryByAnswerIdForDelete(answer.Id, sdkContext)
                                        .ToListAsync();

                    if (answer.WorkflowState == Constants.WorkflowStates.Removed)
                    {
                        return(new OperationResult(
                                   false,
                                   _localizationService.GetString("AnswerRemoved")));
                    }

                    if (answersValues == null)
                    {
                        return(new OperationResult(
                                   false,
                                   _localizationService.GetString("AnswerValuesNotFound")));
                    }

                    foreach (var answersValue in answersValues)
                    {
                        await answersValue.Delete(sdkContext);
                    }

                    await answer.Delete(sdkContext);

                    return(new OperationResult(
                               true,
                               _localizationService.GetString("AnswerAndAnswerValuesHasBeenRemoved")));
                }
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                _logger.LogError(e.Message);
                return(new OperationResult(
                           false,
                           _localizationService.GetString("ErrorWhileRemovingAnswerAndAnswerValues")));
            }
        }
예제 #8
0
        public void ProcessedQuery_CheckingQueryAnswerAppropriate()
        {
            // arrange
            #region Timer
            Timer timer = new Timer();
            timer.Interval  = 30;
            timer.AutoReset = true;
            timer.Elapsed  += TimerElapsed_CheckingQueryAnswerAppropriate;
            timer.Start();
            #endregion

            int      countQueries = 1000;
            string[] ids          = new string[countQueries];
            var      queries      = new List <QueryInfo>();
            var      answers      = new List <AnswerInfo>();
            var      queryHelper  = new QueryHelper();
            var      answerHelper = new AnswerHelper();
            Core.LogChange += CQG_LogChange;
            UnitTestHelper.StartUp();

            //Generate values array
            for (int i = 0; i < ids.Length; i++)
            {
                ids[i] = string.Concat("key", i.ToString());
            }

            // act
            for (int i = 0; i < ids.Length; i++)
            {
                var query = Core.CreateQuery(QueryType.CallCtor, ids[i], string.Empty, string.Empty, string.Empty);
                queries.Add(query);
            }

            foreach (var query in queries)
            {
                Task.Run(async() =>
                {
                    await queryHelper.PushQueryAsync(query);
                }).GetAwaiter().GetResult();
            }

            foreach (var id in ids)
            {
                var answer = answerHelper.GetAnswerData(id);
                answers.Add(answer);
            }

            // assert
            Assert.AreEqual(countQueries, queries.Count);
            Assert.AreEqual(countQueries, answers.Count);
            for (int i = 0; i < answers.Count; i++)
            {
                Assert.IsTrue(queries[i].QueryKey == answers[i].AnswerKey);
            }
        }
예제 #9
0
        public async Task Delete_Answer()
        {
            var answerBeforeDelete = await AnswerHelper.GetAnswerQueryByMicrotingUidForDelete(MicrotingUid, DbContext)
                                     .FirstOrDefaultAsync();

            var answerForBackup = await AnswerHelper.GetAnswerQueryByMicrotingUidForDelete(MicrotingUid, DbContext)
                                  .AsNoTracking()
                                  .FirstOrDefaultAsync();

            var answersValuesBeforeDelete = await AnswerHelper.GetAnswerValuesQueryByAnswerIdForDelete(1, DbContext)
                                            .ToListAsync();

            var answerValuesForBackup = await AnswerHelper.GetAnswerValuesQueryByAnswerIdForDelete(1, DbContext)
                                        .AsNoTracking()
                                        .ToListAsync();

            Assert.IsNotEmpty(answersValuesBeforeDelete);

            foreach (var answersValue in answersValuesBeforeDelete)
            {
                await answersValue.Delete(DbContext);
            }

            Assert.AreNotEqual(answerBeforeDelete, default);
            await answerBeforeDelete.Delete(DbContext);

            var answerAfterDelete = await AnswerHelper.GetAnswerQueryByMicrotingUidForDelete(MicrotingUid, DbContext)
                                    .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed).AsNoTracking()
                                    .FirstOrDefaultAsync();

            var answersValuesAfterDelete = await AnswerHelper.GetAnswerValuesQueryByAnswerIdForDelete(1, DbContext)
                                           .Where(x => x.WorkflowState != Constants.WorkflowStates.Removed).AsNoTracking()
                                           .ToListAsync();

            Assert.IsEmpty(answersValuesAfterDelete);
            Assert.AreEqual(answerAfterDelete, default);

            answerBeforeDelete.Version       = answerForBackup.Version;
            answerBeforeDelete.WorkflowState = answerForBackup.WorkflowState;
            answerBeforeDelete.UpdatedAt     = answerForBackup.UpdatedAt;
            DbContext.Answers.Update(answerBeforeDelete);
            for (var i = 0; i < answersValuesBeforeDelete.Count; i++)
            {
                answersValuesBeforeDelete[i].Version       = answerValuesForBackup[i].Version;
                answersValuesBeforeDelete[i].WorkflowState = answerValuesForBackup[i].WorkflowState;
                answersValuesBeforeDelete[i].UpdatedAt     = answerValuesForBackup[i].UpdatedAt;
                DbContext.AnswerValues.Update(answersValuesBeforeDelete[i]);
            }

            await DbContext.SaveChangesAsync();
        }
예제 #10
0
        public ActionResult MyStatus(long?qid)
        {
            IEnumerable <DataRow> Ld;

            if (qid.HasValue)
            {
            }
            else
            {
                Ld = AnswerHelper.MySatus(DB, User.Identity.Name);
            }

            return(View());
        }
        public ResultMessage SetExamAnswer(ExamAnswer request)
        {
            ExamAnswerHelper eah    = new ExamAnswerHelper();
            ResultMessage    result = eah.Create(request.GUID = Guid.NewGuid().ToString(), request.ExamPaper, request.UserCode, request.ClientIP, request.LeftTime, request.RightTime, request.TotalScore);

            if (!result.State)
            {
                return(result);
            }

            AnswerHelper     ah  = new AnswerHelper();
            AnswerItemHelper aih = new AnswerItemHelper();

            if (request.Answers == null || request.Answers.Count == 0)
            {
                return(result);
            }
            foreach (var a in request.Answers)
            {
                result = ah.Create(a.GUID = Guid.NewGuid().ToString(), a.Ref_ExamAnswer_GUID = request.GUID, a.Code, a.Score, a.Comment);
                if (!result.State)
                {
                    return(result);
                }

                if (a.Answers == null || a.Answers.Count == 0)
                {
                    continue;
                }
                foreach (var ai in a.Answers)
                {
                    if (string.IsNullOrWhiteSpace(ai.ItemOrder))
                    {
                        continue;
                    }
                    result = aih.Create(ai.GUID = Guid.NewGuid().ToString(), ai.Answer_GUID = a.GUID, ai.ItemOrder, ai.Value, ai.ExpandValue);
                    if (!result.State)
                    {
                        return(result);
                    }
                }
            }
            return(result);
        }
예제 #12
0
        protected void btnNext_Click(object sender, EventArgs e)
        {
            //validate
            AnswerSheet   answerSheet      = AnswerHelper.GetAnswerSheet(this.UserId, this.ExamId);
            List <string> checkedOptionIds = new List <string>();

            foreach (RepeaterItem item in repOptions.Items)
            {
                if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                {
                    var chkOption   = item.FindControl("chkOption") as CheckBox;
                    var litOptionId = item.FindControl("litOptionId") as Literal;

                    if (chkOption.Checked)
                    {
                        checkedOptionIds.Add(litOptionId.Text);
                    }
                }
            }
            if (checkedOptionIds.Count > 0)
            {
                if (answerSheet == null)
                {
                    answerSheet = new AnswerSheet()
                    {
                        Answers = new List <Answer>()
                    };
                }

                if (!answerSheet.Answers.Any(x => x.QuestionId == litId.Text))
                {
                    answerSheet.Answers.Add(new Answer()
                    {
                        QuestionId        = litId.Text,
                        SelectedOptionIds = checkedOptionIds
                    });
                    ExamHelper.SaveAnswerSheet(this.UserId, this.ExamId, answerSheet);
                }
            }
            _SetUIAndBindData();
        }
예제 #13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Exm exam = ExamHelper.GetExam(this.ExamId);

            if (IsAnswerMode)
            {
                AnswerSheet answersheet = AnswerHelper.GetAnswerSheet(this.SubmittedUserId, this.ExamId);
                //feed submitted answers
                exam = ExamHelper.ProcessAnswers(exam, answersheet);
                divExamDetails.Visible = false;
            }

            if (exam != null)
            {
                litIstructions.Text = exam.Instructions != null ? exam.Instructions : "-";
                litTime.Text        = exam.TimeInSeconds.HasValue ? Utils.TimeString(exam.TimeInSeconds.Value) : "-";

                repQuestions.DataSource = exam.Questions;
                repQuestions.DataBind();
            }
        }
예제 #14
0
        //10 sec act test
        public async void ProcessedQuery_WithLongAct()
        {
            // arrange
            string id   = "key";
            string name = "name";
            bool   isQuery;
            var    queryHelper  = new QueryHelper();
            var    answerHelper = new AnswerHelper();

            Core.LogChange += CQG_LogChange;
            UnitTestHelper.StartUp();

            // act
            var query = Core.CreateQuery(QueryType.CallCtor, id, string.Empty, name, string.Empty);
            await queryHelper.PushQueryAsync(query);

            isQuery = await UnitTestHelper.QueryHandler.CheckQueryAsync(id);

            // assert 1
            Assert.IsTrue(isQuery);

            UnitTestHelper.QueryHandler.ProcessQuery(query);

            //Waight some time after procssed query
            Task.Delay(10000).GetAwaiter().GetResult();

            Task.Run(async() =>
            {
                isQuery = await UnitTestHelper.QueryHandler.CheckQueryAsync(id);

                // assert 2
                Assert.IsFalse(isQuery);
            }).GetAwaiter().GetResult();

            var answer = answerHelper.GetAnswerData(id);

            // assert 3
            Assert.IsNotNull(answer);
            Assert.AreEqual(id, answer.AnswerKey);
        }
        public async Task <OperationDataResult <AnswerViewModel> > GetAnswerByMicrotingUid(int microtingUid)
        {
            try
            {
                var core = await _coreHelper.GetCore();

                AnswerViewModel result;
                await using (var sdkContext = core.DbContextHelper.GetDbContext())
                {
                    var answersQueryable = AnswerHelper.GetAnswerQueryByMicrotingUid(microtingUid, sdkContext);

                    result = answersQueryable.FirstOrDefault();
                }

                if (result == null)
                {
                    return(new OperationDataResult <AnswerViewModel>(
                               false,
                               _localizationService.GetString("AnswerNotFound")));
                }

                if (result.AnswerValues == null)
                {
                    return(new OperationDataResult <AnswerViewModel>(
                               false,
                               _localizationService.GetString("AnswerValuesNotFound")));
                }

                return(new OperationDataResult <AnswerViewModel>(true, result));
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                _logger.LogError(e.Message);
                return(new OperationDataResult <AnswerViewModel>(false,
                                                                 _localizationService.GetString("ErrorWhileObtainingGetAnswer")));
            }
        }
예제 #16
0
        public void Method_PushAnswer()
        {
            // arrange
            string id           = "key";
            string name         = "name";
            bool   isQueryTrue  = default(bool);
            bool   isQueryFalse = default(bool);
            var    query        = new QueryInfo(QueryType.SetProperty, id, string.Empty, name, null, null);
            var    answer       = new AnswerInfo(id, string.Empty, name, null, null);

            Core.LogChange += CQG_LogChange;
            var queryHelper  = new QueryHelper();
            var answerHelper = new AnswerHelper();

            UnitTestHelper.StartUp();
            Task.Run(async() =>
            {
                await answerHelper.ClearAnswersListAsync();
            }).GetAwaiter().GetResult();

            // act
            Task.Run(async() =>
            {
                await queryHelper.PushQueryAsync(query);
                isQueryTrue = await UnitTestHelper.QueryHandler.CheckQueryAsync(id);
            }).GetAwaiter().GetResult();

            UnitTestHelper.QueryHandler.PushAnswerAndDeleteQuery(answer);

            Task.Run(async() =>
            {
                isQueryFalse = await UnitTestHelper.QueryHandler.CheckQueryAsync(id);
            }).GetAwaiter().GetResult();

            // assert
            Assert.IsTrue(isQueryTrue);
            Assert.IsFalse(isQueryFalse);
        }
예제 #17
0
        public void Answer_Get()
        {
            var answer = AnswerHelper.GetAnswerQueryByMicrotingUid(MicrotingUid, DbContext).FirstOrDefault();

            Assert.NotNull(answer);
            Assert.AreEqual(answer.Id, _answerForTest.Id);
            Assert.AreEqual(answer.MicrotingUid, _answerForTest.MicrotingUid);
            for (var i = 0; i < _answerForTest.AnswerValues.Count; i++)
            {
                var answerValues        = answer.AnswerValues[i];
                var answerValuesForTest = _answerForTest.AnswerValues[i];
                Assert.AreEqual(answerValues.Id, answerValuesForTest.Id);
                Assert.AreEqual(answerValues.Value, answerValuesForTest.Value);
                for (var j = 0; j < answerValuesForTest.Translations.Count; j++)
                {
                    var translationsForTest = answerValuesForTest.Translations[j];
                    var translations        = answerValues.Translations[j];
                    Assert.AreEqual(translations.LanguageId, translationsForTest.LanguageId);
                    Assert.AreEqual(translations.LanguageName, translationsForTest.LanguageName);
                    Assert.AreEqual(translations.Value, translationsForTest.Value);
                }
            }
        }
예제 #18
0
        private void _SetUIAndBindData()
        {
            Exm exam = ExamHelper.GetExam(this.ExamId);

            AnswerSheet answersheet = AnswerHelper.GetAnswerSheet(this.UserId, this.ExamId);

            if (!Page.IsPostBack)
            {
                divQuestionContainer.Visible = false;
                divMessage.Visible           = false;
                divWelcome.Visible           = true;

                litIstructions.Text = exam.Instructions != null ? exam.Instructions : "-";
                litTime.Text        = exam.TimeInSeconds.HasValue ? Utils.TimeString(exam.TimeInSeconds.Value) : "-";
                return;
            }
            else if (answersheet != null && answersheet.Answers.Count == exam.Questions.Count)
            {
                divQuestionContainer.Visible = false;
                divMessage.Visible           = true;
                divWelcome.Visible           = false;

                //lblMessage.Text = "Finished!";
            }
            else if (answersheet == null || answersheet.Answers.Count < exam.Questions.Count)
            {
                divQuestionContainer.Visible = true;
                divMessage.Visible           = false;
                divWelcome.Visible           = false;
                Question question = ExamHelper.NextQuestion(exam, answersheet);
                if (question != null)
                {
                    populateQuestionUI(question);
                }
            }
        }
예제 #19
0
 public override string GetStringAnswer()
 {
     return(AnswerHelper.GetAnswer(Answer));
 }
 public override string GetStringAnswer()
 {
     return(AnswerHelper.GetAnswer(Answer, ReadableOptions));
 }
예제 #21
0
            // Main method that contains all parts of executing the query on application side
            public static object ExecuteTheQuery(
                QueryType queryType,
                string dcObjType = null,
                string dcObjKey  = null,
                string memName   = null,
                object[] args    = null)
            {
                if (FirstCall)
                {
                    // Lazy connection to MongoDB
                    QueryHelper  = new QueryHelper();
                    AnswerHelper = new AnswerHelper();
                    EventHelper  = new EventHelper();

                    isDCClosedChekingTimer.Interval  = isDCClosedChekingInterval;
                    isDCClosedChekingTimer.Elapsed  += isDCClosedChekingTimer_Tick;
                    isDCClosedChekingTimer.AutoReset = false;
                    isDCClosedChekingTimer.Enabled   = true;
                }

                Dictionary <int, string> argKeys;
                Dictionary <int, object> argVals;

                PutArgsFromArrayIntoTwoDicts(args, true, out argKeys, out argVals);

                string queryKey = CreateUniqueKey();

                QueryInfo queryInfo = CreateQuery(queryType, queryKey, dcObjType, dcObjKey, memName, argKeys, argVals);

                QueryHelper.PushQuery(queryInfo);

                AnswerInfo result = WaitingForAnAnswer(queryKey, queryType);

                if (FirstCall)
                {
                    // Start handshaking
                    Subscriber.ListenForHanshaking();

                    FirstCall = false;
                }

                if (result == null)
                {
                    return(default(object));
                }

                if (result.IsCQGException)
                {
                    var exception = new Exception(result.CQGException.Message);
                    exception.Source = result.CQGException.Source;
                    throw exception;
                }

                if (result.ValueKey == "value")
                {
                    return(result.Value);
                }
                else if (result.ValueKey == "true")
                {
                    return(true);
                }
                else
                {
                    return(result.ValueKey);
                }
            }
        private void countryNameEnterButton_Click(object sender, EventArgs e)
        {
            countryInfoDataGridView.Rows.Clear();
            var request = RequestHelper.CreateRequest(countryNameTextBox.Text);

            try
            {
                using (var response = request.GetResponse())
                {
                    var answer = AnswerHelper.GetAnswer(response);

                    if (JsonConvert.DeserializeObject <List <City> >(answer).Count > 1)
                    {
                        throw new ArgumentOutOfRangeException(
                                  "Слишком много стран по данному запросу. Введите более точное название!");
                    }

                    var countryFromApi = CountryFromApi.GetCountryFromApi(answer);
                    countryInfoDataGridView.Rows.Add(countryFromApi.Name,
                                                     countryFromApi.Code,
                                                     countryFromApi.Capital,
                                                     countryFromApi.Area,
                                                     countryFromApi.Population,
                                                     countryFromApi.Region);

                    var dialogResult = MessageBox.Show("Хотите ли сохранить город в базу данных?",
                                                       "",
                                                       MessageBoxButtons.YesNo,
                                                       MessageBoxIcon.Question);
                    if (dialogResult == DialogResult.Yes)
                    {
                        var query   = new DbQueries();
                        var capital = query.GetCapital(answer);
                        var region  = query.GetRegion(answer);
                        query.AddCountryInDb(countryFromApi, capital, region);
                    }
                }
            }
            catch (WebException ex)
            {
                MessageBox.Show("Страны с таким именем не существует!",
                                "Ошибка",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            catch (JsonSerializationException ex)
            {
                MessageBox.Show(
                    "Произошла ошибка при обработке информации о стране (Возможно, введено некорректное название)!",
                    "Ошибка",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,
                                "Ошибка",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }