示例#1
0
        public async Task Success_FeedbackController_CreateSessionFeedback_Created()
        {
            //Arrange
            var sessionId = "someSessionId";
            var userId    = "someUserId";
            var feedback  = new SessionFeedback()
            {
                Comment   = "",
                Id        = "",
                Rate      = 5,
                SessionId = sessionId,
                UserId    = userId
            };

            _mockFeedbackService.Setup(service => service.CreateFeedbackAsync(It.IsAny <SessionFeedback>()))
            .ReturnsAsync(feedback);
            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Ubi-UserId"] = "1234566";

            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext
            };

            //Act
            var feedbackController = new FeedbackController(_mockLogger.Object, _mockFeedbackService.Object)
            {
                ControllerContext = controllerContext
            };
            var action = await feedbackController.CreateSessionFeedback(sessionId, new SessionFeedback()
            {
                Comment = "", Rate = 4
            });

            var result = action.Result as StatusCodeResult;

            //Assert
            Assert.IsType <StatusCodeResult>(result);
            Assert.Equal(201, result.StatusCode);
            _mockFeedbackService.Verify(service => service.CreateFeedbackAsync(It.IsAny <SessionFeedback>()), Times.Once);
        }
示例#2
0
        public async Task Fail_FeedbackController_CreateSessionFeedback_BadRequest_When_Feedback_Allready_Exists()
        {
            //Arrange
            var sessionId = "someSessionId";
            var userId    = "someUserId";
            var feedback  = new SessionFeedback()
            {
                Comment   = "",
                Id        = "",
                Rate      = 5,
                SessionId = sessionId,
                UserId    = userId
            };

            _mockFeedbackService.Setup(service => service.CreateFeedbackAsync(It.IsAny <SessionFeedback>()))
            .ThrowsAsync(CreateDuplicateMongoWriteException());
            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Ubi-UserId"] = "1234566";

            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext
            };

            //Act
            var feedbackController = new FeedbackController(_mockLogger.Object, _mockFeedbackService.Object)
            {
                ControllerContext = controllerContext
            };
            var action = await feedbackController.CreateSessionFeedback(sessionId, new SessionFeedback()
            {
                Comment = "", Rate = 4
            });

            var result = action.Result as ConflictResult;

            //Assert
            Assert.IsType <ConflictResult>(result);
            _mockFeedbackService.Verify(service => service.CreateFeedbackAsync(It.IsAny <SessionFeedback>()), Times.Once);
        }
示例#3
0
        public async Task Fail_FeedbackController_CreateSessionFeedback_BadRequest_When_Wrong_Header(string headerValue)
        {
            //Arrange
            var sessionId = "someSessionId";
            var userId    = "someUserId";
            var feedback  = new SessionFeedback()
            {
                Comment   = "",
                Id        = "",
                Rate      = 5,
                SessionId = sessionId,
                UserId    = userId
            };

            _mockFeedbackService.Setup(service => service.CreateFeedbackAsync(It.IsAny <SessionFeedback>()))
            .ReturnsAsync(feedback);
            var httpContext = new DefaultHttpContext();

            httpContext.Request.Headers["Ubi-UserId"] = headerValue;

            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext
            };

            //Act
            var feedbackController = new FeedbackController(_mockLogger.Object, _mockFeedbackService.Object)
            {
                ControllerContext = controllerContext
            };
            var action = await feedbackController.CreateSessionFeedback(sessionId, new SessionFeedback()
            {
                Comment = "", Rate = 4
            });

            var result = action.Result as BadRequestResult;

            //Assert
            Assert.IsType <BadRequestResult>(result);
            _mockFeedbackService.Verify(service => service.CreateFeedbackAsync(It.IsAny <SessionFeedback>()), Times.Never);
        }