コード例 #1
0
        public async void DeleteQuestion_UnknownId_ReturnsBadRequestResult()
        {
            // Arrange
            var mock = new Mock <IQuestionService>();

            mock.Setup(s => s.DeleteAsync(It.IsAny <int>())).Returns((int id) => FakeServicesMethods.DeleteQuestion(id));
            var controller = new QuestionController(mock.Object);

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

            var badRequestResult = result as BadRequestResult;

            // Assert
            Assert.NotNull(badRequestResult);
        }
コード例 #2
0
        public async void DeleteQuestion_CorrectId_ReturnsOk()
        {
            // Arrange
            var mock = new Mock <IQuestionService>();

            mock.Setup(s => s.DeleteAsync(It.IsAny <int>())).Returns((int id) => FakeServicesMethods.DeleteQuestion(id));
            var controller = new QuestionController(mock.Object);

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

            var okResult = result as OkResult;

            // Assert
            Assert.NotNull(okResult);
            Assert.Equal(200, okResult.StatusCode);
        }