public async Task Check_If_Query_Was_Added()
        {
            await LogInAsAdministrator();

            var createQuestion = new CreateQuestion(
                questionText: "Some question?",
                answers: new[] { "First answer", "Second answer" });
            var createQuestionResponse = await Mediator.Send(createQuestion);

            var getQuestions      = new GetQuestions();
            var questionsResponse = await Mediator.Send(getQuestions);

            var addedQuestionId = AssertNotError.Of(createQuestionResponse);
            var allQuestions    = AssertNotError.Of(questionsResponse);

            var questionThatWasAdded = allQuestions.Questions.SingleOrDefault(q => q.Id == addedQuestionId);

            Assert.That(questionThatWasAdded, Is.Not.Null);
            Assert.Multiple(() =>
            {
                Assert.That(
                    questionThatWasAdded !.QuestionText,
                    Is.EqualTo(createQuestion.QuestionText));

                CollectionAssert.AreEqual(
                    questionThatWasAdded.Answers.Select(a => a.Text),
                    createQuestion.Answers);
            });
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetAll()
        {
            var request  = new GetQuestions();
            var response = await _mediator.Send(request);

            return(HandleErrors(response, Ok));
        }
        public IActionResult Load(long?ID, long?QusType, long?QusID, long?langId)
        {
            GetQuestions operation = new GetQuestions();

            operation.ID              = ID;
            operation.QustionType     = QusType;
            operation.QuestionnaireID = QusID;

            if (langId.HasValue)
            {
                operation.LangID = langId;
            }
            else
            {
                operation.LangID = 1;
            }

            var result = operation.QueryAsync().Result;

            if (result is ValidationsOutput)
            {
                return(Ok(new ApiResult <List <ValidationItem> >()
                {
                    Data = ((ValidationsOutput)result).Errors
                }));
            }
            else
            {
                return(Ok((List <Question>)result));
            }
        }
        public async Task Create_3_Questions_And_Check_If_Added()
        {
            await LogInAsAdministrator();

            var createFirstQuestion = new CreateQuestion(
                questionText: "Some question?",
                answers: new[] { "First answer", "Second answer" });
            var createFirstQuestionResponse = await Mediator.Send(createFirstQuestion);

            var firstQuestionId = AssertNotError.Of(createFirstQuestionResponse);

            var createSecondQuestion = new CreateQuestion(
                questionText: "Another question?",
                answers: new[] { "Any answer", "Some answer" });
            var createSecondQuestionResponse = await Mediator.Send(createSecondQuestion);

            var secondQuestionId = AssertNotError.Of(createSecondQuestionResponse);

            var createThirdQuestion = new CreateQuestion(
                questionText: "Third question?",
                answers: new[] { "Any answer", "Some answer", "I don't know answer" });
            var createThirdQuestionResponse = await Mediator.Send(createThirdQuestion);

            var thirdQuestionId = AssertNotError.Of(createThirdQuestionResponse);

            await LogInAsVoter();

            var expectedQuestions = new Dictionary <Guid, CreateQuestion>
            {
                [firstQuestionId]  = createFirstQuestion,
                [secondQuestionId] = createSecondQuestion,
                [thirdQuestionId]  = createThirdQuestion
            };

            var getQuestions         = new GetQuestions();
            var getQuestionsResponse = await Mediator.Send(getQuestions);

            var questions = AssertNotError.Of(getQuestionsResponse);

            Assert.That(questions.Questions, Has.Count.EqualTo(3));

            CollectionAssert.AreEquivalent(
                expectedQuestions.Select(q => q.Value.QuestionText),
                questions.Questions.Select(q => q.QuestionText));

            foreach (var question in questions.Questions)
            {
                var expectedAnswers = expectedQuestions
                                      .Single(q => q.Key == question.Id)
                                      .Value
                                      .Answers;

                CollectionAssert.AreEqual(
                    expectedAnswers,
                    question.Answers.Select(a => a.Text));
            }
        }
        public async void Test16()
        {
            GetQuestions getQuestions = new GetQuestions();
            await getQuestions.GetNextQuestions(new[] { "" });

            string serializedQuestion     = JsonConvert.SerializeObject(GetQuestions.question);
            string serializedNullQuestion = JsonConvert.SerializeObject(new RequestResponse());

            Assert.NotEqual(serializedNullQuestion, serializedQuestion);
        }
        public async void getNextQuestion()
        {
            GetQuestions  getQuestions = new GetQuestions();
            QuestionBlock block        = await getQuestions.Question();

            if (block != null)
            {
                panelForQuestion.Children.Add(block);
                count += 1;
            }
        }
        public static async Task <QuestionViewModel?> AskToSelectQuestion(IMediator mediator)
        {
            var getQuestions = new GetQuestions();
            QuestionsListViewModel getQuestionsResponse;

            try
            {
                getQuestionsResponse = await mediator.Send(getQuestions)
                                       .OnError(error => throw new InvalidOperationException(error.ToString()));
            }
            catch (Exception exception)
            {
                exception.WriteToConsole();
                return(default);
Exemplo n.º 8
0
        private void getQuestionList()
        {
            //FOR LISTING AUTHORISED MACHINES
            Console.WriteLine("clearing all view list data");
            listView1.Clear();


            //GET DATA
            string       apiUrl           = "https://craig.im/infosec.php";
            string       apiMethod        = "getQuestions";
            GetQuestions thisGetQuesitons = new GetQuestions()
            {
            };


            //Make http post request
            string response = Http.Post(apiUrl, new NameValueCollection()
            {
                { "api_method", apiMethod },
                { "api_data", JsonConvert.SerializeObject(thisGetQuesitons) }
            });

            //Deserialise
            API_Response r = JsonConvert.DeserializeObject <API_Response>(response);

            //MessageBox.Show("" + r.ResponseData[0].commonName);

            // Set to details view.
            listView1.View = View.Details;
            // Add both columns.
            listView1.Columns.Add("ID", 25, HorizontalAlignment.Left);
            listView1.Columns.Add("Question", 150, HorizontalAlignment.Left);
            listView1.Columns.Add("Answer A", 60, HorizontalAlignment.Left);
            listView1.Columns.Add("Answer B", 60, HorizontalAlignment.Left);
            listView1.Columns.Add("Correct Answer", 85, HorizontalAlignment.Left);

            //fill with data
            int lim = r.ResponseData.Length;

            for (int i = 0; i <= (lim - 1); i++)
            {
                Console.WriteLine("This is loop number " + i);
                string[] row1         = { r.ResponseData[i].questionID, r.ResponseData[i].question, r.ResponseData[i].answerA, r.ResponseData[i].answerB, r.ResponseData[i].correctAnswer };
                var      listViewItem = new ListViewItem(row1);
                listView1.Items.Add(listViewItem);
                row1 = null;
            }
        }
Exemplo n.º 9
0
        public void FailedToGetQuestions()
        {
            LoginDTO username = new LoginDTO()
            {
                UserName = "******"
            };

            GetQuestions failedToGet = new GetQuestions()
            {
                loginDTO = username
            };

            var response = (ResetPasswordResponseDTO)failedToGet.Execute().Result;

            Assert.False(response.isSuccessful);
        }
 private void PreviousButton_Click(object sender, RoutedEventArgs e)
 {
     if (count == 0)
     {
         GetQuestions.question = new Models.RequestResponse();
         MainWindow mainWindow = new MainWindow();
         mainWindow.Show();
         this.Close();
     }
     else
     {
         GetQuestions getQuestions = new GetQuestions();
         getQuestions.SetPreviousQuestion();
         panelForQuestion.Children.RemoveAt(count);
         count -= 1;
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// Get questions for user
        /// </summary>
        /// <param name="loginDTO">user</param>
        /// <returns>user's security questions</returns>
        public ResetPasswordResponseDTO GetQuestions(UserCredential userCredential)
        {
            LoginDTO loginDTO = new LoginDTO()
            {
                UserName = userCredential.Username
            };

            ResetPasswordResponseDTO response = new ResetPasswordResponseDTO();

            GetQuestions getQuestions = new GetQuestions()
            {
                loginDTO = loginDTO
            };

            response = (ResetPasswordResponseDTO)getQuestions.Execute().Result;

            return(response);
        }
Exemplo n.º 12
0
        public void GetQuestions()
        {
            LoginDTO username = new LoginDTO()
            {
                UserName = "******"
            };

            GetQuestions failedToGet = new GetQuestions()
            {
                loginDTO = username
            };

            var response = (ResetPasswordResponseDTO)failedToGet.Execute().Result;

            Assert.True(response.isSuccessful);
            Assert.Equal("Where did you go to highschool or college?", response.Questions[2]);
            Assert.Equal("What is your favorite sports team?", response.Questions[6]);
            Assert.Equal("In what city or town does your nearest sibling live?", response.Questions[9]);
        }
Exemplo n.º 13
0
        private string getQuestions()
        {
            //GET DATA
            string       apiUrl       = "https://craig.im/infosec.php";
            string       apiMethod    = "getQuestions";
            GetQuestions thisGetUsers = new GetQuestions()
            {
            };


            //Make http post request
            string response = Http.Post(apiUrl, new NameValueCollection()
            {
                { "api_method", apiMethod },
                { "api_data", JsonConvert.SerializeObject(thisGetUsers) }
            });

            return(response);
        }
        public async void QuestionAccordingToChoices()
        {
            if (GetQuestions.choicesMade == "Yes,")
            {
                GetProductList productList = new GetProductList();
                await productList.GetProductsMatchingTheChoices(GetQuestions.question);

                QuestionBlock display = productList.GetQuestion();
                panelForQuestion.Children.Add(display);
                count += 1;
            }
            else
            {
                GetQuestions getQuestions = new GetQuestions();
                getQuestions.SetPreviousQuestion();
                panelForQuestion.Children.RemoveAt(count);
                count -= 1;
            }
        }
        public override async Task Execute(IReadOnlyList <string> args)
        {
            var getQuestions = new GetQuestions();

            QuestionsListViewModel getQuestionsResponse;

            try
            {
                getQuestionsResponse = await _mediator.Send(getQuestions)
                                       .OnError(error => throw new InvalidOperationException(error.ToString()));
            }
            catch (Exception exception)
            {
                exception.WriteToConsole();
                return;
            }

            Console.WriteLine();
            Console.WriteLine(getQuestionsResponse.ToString());
            Console.WriteLine();
        }
Exemplo n.º 16
0
        public async Task VoteRandomly()
        {
            if (_voterIdentity is null)
            {
                throw new InvalidOperationException(
                          $"call {nameof(LogInAsRandomVoter)} before");
            }

            await using var scope = _container.BeginLifetimeScope();
            var mediator = scope.Resolve <IMediator>();

            var authenticationService = scope.Resolve <AuthenticationService>();

            authenticationService.SetIdentity(_voterIdentity);

            var getQuestions         = new GetQuestions();
            var getQuestionsResponse = await mediator.Send(getQuestions);

            var questionsList = getQuestionsResponse
                                .OnError(error => throw new InvalidOperationException(error.ToString()));

            foreach (var question in questionsList.Questions)
            {
                var answerGuids = question.Answers
                                  .Select(a => a.Id)
                                  .ToArray();

                var selectedAnswerId = GetRandomGuid(answerGuids);

                var voteFor = new VoteFor(
                    questionId: question.Id,
                    answerId: selectedAnswerId);

                await mediator.Send(voteFor)
                .OnError(error => throw new InvalidOperationException(error.ToString()));
            }
        }
Exemplo n.º 17
0
 public object Get(GetQuestions request)
 {
     return(new QuestionResponse {
         Results = Db.Select <SQuestion>()
     });
 }
Exemplo n.º 18
0
 public MainWindow()
 {
     InitializeComponent();
     GetQuestions.Get(new GetQuestionsFromExcel());
     this.DataContext = new MainWindowViewModel();
 }