Пример #1
0
        public async Task ShouldCreateNewQuestion()
        {
            var questionDto = new AddQuestionWithWrittenAnswerDto
            {
                Answer   = "answer",
                Question = "question",
                Score    = 1.5f
            };

            var json     = fixture.Serialize(questionDto);
            var response = await fixture.RequestSender.PostAsync($"questions", json);

            response.StatusCode.Should().Be(HttpStatusCode.OK);
            var responseData = await response.Content.ReadAsStringAsync();

            int questionId;

            int.TryParse(responseData, out questionId).Should().BeTrue();
            var created = await fixture.ExecuteDbContext(db => db.Questions.Include(x => x.Answer).FirstOrDefaultAsync(x => x.Id == questionId));

            created.Content.Should().Be(questionDto.Question);
            var answer = created.Answer as WrittenAnswer;

            answer.Value.Should().Be(questionDto.Answer);
            answer.MaxScore.Should().Be(questionDto.Score);
        }
Пример #2
0
        public async Task ShouldNotCreateNewQuestionBecauseDtoIsNotValid()
        {
            var questionDtoWithEmptyAnswerField = new AddQuestionWithWrittenAnswerDto
            {
                Answer   = "",
                Question = "question",
                Score    = 1.5f
            };

            var json     = fixture.Serialize(questionDtoWithEmptyAnswerField);
            var response = await fixture.RequestSender.PostAsync($"questions", json);

            var responseJson = await response.Content.ReadAsStringAsync();

            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
            var validationError = fixture.Deserialize <ValidationErrorResponse>(responseJson);

            validationError.Errors.Should().ContainKey("Answer");
        }