コード例 #1
0
        public void Get_SurveyIdPassed_ReturnsOkObjectResult()
        {
            // Arrange
            var id = 2;

            // Act
            var result = _controller.GetSurvey(id);

            // Assert
            Assert.IsType <OkObjectResult>(result);
        }
コード例 #2
0
        public void Getsurvey_ShouldNotFindsurvey()
        {
            var controller = new SurveyController(GetTestSurvey());

            var result = controller.GetSurvey(3);

            Assert.IsInstanceOfType(result, typeof(Activity));
        }
コード例 #3
0
        public void GetSurvey_ShouldReturnCorrectSurvey()
        {
            var testSurvey = GetTestSurvey();
            var controller = new SurveyController(testSurvey);

            var result = controller.GetSurvey(3);

            Assert.IsNotNull(result);
            Assert.AreEqual(testSurvey[0].heading, result.heading);
        }
コード例 #4
0
        public async void GetSurvey_UnknownId_ReturnsNotFoundResult()
        {
            // Arrange
            var mock = new Mock <ISurveyService>();

            mock.Setup(s => s.GetAsync(It.IsAny <int>())).Returns((int id) => FakeServicesMethods.GetSurvey(id));
            var controller = new SurveyController(mock.Object);

            // Act
            var result = await controller.GetSurvey(0);

            var notFoundResult = result as NotFoundResult;

            // Assert
            Assert.NotNull(notFoundResult);
        }
コード例 #5
0
        public async void GetSurvey_CorrectId_ReturnsOk()
        {
            // Arrange
            var mock = new Mock <ISurveyService>();

            mock.Setup(s => s.GetAsync(It.IsAny <int>())).Returns((int id) => FakeServicesMethods.GetSurvey(id));
            var controller = new SurveyController(mock.Object);

            // Act
            var result = await controller.GetSurvey(1);

            var okResult = result as OkObjectResult;

            // Assert
            Assert.NotNull(okResult);
            Assert.Equal(200, okResult.StatusCode);
        }
コード例 #6
0
        public async void GetSurvey_CorrectId_ReturnsRightItem()
        {
            // Arrange
            var mock = new Mock <ISurveyService>();

            mock.Setup(s => s.GetAsync(It.IsAny <int>())).Returns((int id) => FakeServicesMethods.GetSurvey(id));
            var controller = new SurveyController(mock.Object);

            // Act
            var result = await controller.GetSurvey(1);

            var okResult = result as OkObjectResult;

            // Assert
            var item = Assert.IsAssignableFrom <SurveyDTO>(okResult.Value);

            Assert.Equal(1, (okResult.Value as SurveyDTO)?.Id);
        }