Esempio n. 1
0
        public async void AddOuestionToSurvey_ValidObjectPassed_ReturnsAllItems()
        {
            // Arrange
            var mock = new Mock <ISurveyService>();

            mock.Setup(s => s.AddQuestionToSurveyAsync(It.IsAny <int>(), It.IsAny <QuestionDTO>())).Returns((int id, QuestionDTO s) => FakeServicesMethods.AddQuestionToSurvey(id, s));
            var controller = new SurveyController(mock.Object);

            // Act
            var question = new QuestionDTO
            {
                Id           = 1,
                Title        = "Question 1",
                QuestionText = "text",
                Comment      = "",
                Answers      = new List <AnswerDTO>()
            };
            var result = await controller.AddOuestionToSurvey(1, question);

            var okResult = result as OkObjectResult;

            // Assert
            Assert.NotNull(okResult);
            Assert.Equal(1, (okResult.Value as SurveyDTO)?.Questions.Count);
        }
Esempio n. 2
0
        public async void AddOuestionToSurvey_InvalidObjectPassed_ReturnsBadRequest()
        {
            // Arrange
            var mock = new Mock <ISurveyService>();

            mock.Setup(s => s.AddQuestionToSurveyAsync(It.IsAny <int>(), It.IsAny <QuestionDTO>())).Returns((int id, QuestionDTO s) => FakeServicesMethods.AddQuestionToSurvey(id, s));
            var controller = new SurveyController(mock.Object);

            // Act
            var result = await controller.AddOuestionToSurvey(1, null);

            var badRequestResult = result as BadRequestResult;

            // Assert
            Assert.NotNull(badRequestResult);
            Assert.Equal(400, badRequestResult.StatusCode);
        }