Esempio n. 1
0
        public void Setup()
        {
            _httpClient      = new HttpClient();
            _usersClient     = new UsersClient(_httpClient);
            _testsClient     = new TestsClient(_httpClient);
            _questionsClient = new QuestionsClient(_httpClient);
            _sut             = new AnswersClient(_httpClient);

            _user = GetRandomUser();
            _usersClient.RegisterUserAsync(_user).GetAwaiter().GetResult();
            _testId = _testsClient.AddAsync().GetAwaiter().GetResult().Deserialize <Guid>();

            for (var i = 0; i < 10; i++)
            {
                _questionsClient.AddAsync(_testId).GetAwaiter().GetResult();
            }

            _questions = _questionsClient.GetListAsync(_testId).GetAwaiter().GetResult().Deserialize <List <QuestionDto> >();
            foreach (var question in _questions)
            {
                question.Question = GetRandomString();
                question.Answer   = GetRandomString();
                _questionsClient.UpdateAsync(question).GetAwaiter().GetResult();
            }
        }
Esempio n. 2
0
        public void Update_AlreadyExistsQuestion_Success()
        {
            var newText = "new text";

            var questionId = _sut.AddAsync(_testId).GetAwaiter().GetResult().Deserialize <Guid>();
            var question   = _sut.GetListAsync(_testId).GetAwaiter().GetResult().Deserialize <List <QuestionDto> >()
                             .Single(q => q.Id == questionId);

            Assert.AreEqual(null, question.Question);
            Assert.AreEqual(null, question.Answer);
            question.Question = newText;
            question.Answer   = newText;

            var response = _sut.UpdateAsync(question).GetAwaiter().GetResult();

            Assert.AreEqual(200, response.StatusCode);

            var updatedQuestion = _sut.GetListAsync(_testId).GetAwaiter().GetResult().Deserialize <List <QuestionDto> >()
                                  .Single(q => q.Id == questionId);

            Assert.AreEqual(newText, updatedQuestion.Question);
            Assert.AreEqual(newText, updatedQuestion.Answer);
        }
        private List <QuestionDto> GenerateQuestion(int questionsCount)
        {
            for (var i = 0; i < questionsCount; i++)
            {
                _questionsClient.AddAsync(_testId).GetAwaiter().GetResult();
            }

            var questions = _questionsClient.GetListAsync(_testId).GetAwaiter().GetResult().Deserialize <List <QuestionDto> >();

            foreach (var question in questions)
            {
                question.Question = GetRandomString();
                question.Answer   = GetRandomString().ToUpper();
                _questionsClient.UpdateAsync(question).GetAwaiter().GetResult();
            }

            return(questions);
        }