Esempio n. 1
0
            public async Task ReturnOk_WhenValidFeedbackIsGivenWithUbiUserIdHeader_And_FeedbackIsSuccessfullySent()
            {
                var ubiUserId   = "player-id-1";
                var requestBody = new PlayerFeedBackRequest
                {
                    SessionId = new Guid("906733a4-f2c9-44c1-9e03-b8a8c5393e18"),
                    Rating    = 5,
                    Comment   = ""
                };

                _mockFeedbackSender
                .Setup(sender => sender.Send(It.IsAny <PlayerFeedbackDto>()))
                .ReturnsAsync(Result.Ok());

                var controller =
                    new PlayerFeedbackController(_mockQueryHandler.Object, _mockFeedbackSender.Object, _mockClock.Object);

                controller.ControllerContext.HttpContext = new DefaultHttpContext();

                UbiUserIdHeaderHelper.AddUbiUserIdsToRequestHeader(
                    controller.ControllerContext.HttpContext.Request,
                    ubiUserId
                    );

                var responseResult = await controller.Post(requestBody);

                var response = Assert.IsType <OkResult>(responseResult);

                Assert.Equal(StatusCodes.Status200OK, response.StatusCode);
            }
            public void ReturnOkWithUbiUserId_WhenHeaderIsPresent()
            {
                var ubiUserId   = "player-id-1";
                var httpContext = new DefaultHttpContext();

                UbiUserIdHeaderHelper.AddUbiUserIdsToRequestHeader(httpContext.Request, ubiUserId);

                var result = UbiUserIdHeader.ExtractUbiUserId(httpContext.Request);

                Assert.True(result.IsOk);
                Assert.Equal(ubiUserId, result.Value);
            }
            public void ReturnOkWithFirstUbiUserId_WhenHeaderIsPresentAndThereAreMultipleIds()
            {
                var ubiUserId1  = "player-id-1";
                var ubiUserId2  = "player-id-2";
                var httpContext = new DefaultHttpContext();

                UbiUserIdHeaderHelper.AddUbiUserIdsToRequestHeader(httpContext.Request, ubiUserId1, ubiUserId2);

                var result = UbiUserIdHeader.ExtractUbiUserId(httpContext.Request);

                Assert.True(result.IsOk);
                Assert.Equal(ubiUserId1, result.Value);
            }
            public void ReturnError_WhenHeaderIsPresentButEmpty()
            {
                var httpContext = new DefaultHttpContext();

                UbiUserIdHeaderHelper.AddUbiUserIdsToRequestHeader(httpContext.Request);

                var result = UbiUserIdHeader.ExtractUbiUserId(httpContext.Request);

                var expectedError = new Error
                {
                    Type    = UbiUserIdHeader.UbiUserIdMissingError,
                    Message = UbiUserIdHeader.UbiUserIdMissingErrorMessage
                };

                Assert.True(result.IsError);
                Assert.Equal(expectedError, result.Error);
            }
Esempio n. 5
0
            public async Task ReturnBadRequest_WhenUbiUserIdIsGiven_But_InvalidFeedbackIsGiven()
            {
                var ubiUserId   = "player-id-1";
                var requestBody = new PlayerFeedBackRequest
                {
                    SessionId = new Guid("906733a4-f2c9-44c1-9e03-b8a8c5393e18"),
                    Rating    = -1,
                    Comment   = ""
                };

                var expectedError = new Error
                {
                    Type    = ErrorType.RatingOutOfRange.ToString(),
                    Message = ErrorMessage.RatingOutOfRangeMessage
                };

                _mockFeedbackSender
                .Setup(sender => sender.Send(It.IsAny <PlayerFeedbackDto>()))
                .ReturnsAsync(Result.Fail(expectedError));

                var controller =
                    new PlayerFeedbackController(_mockQueryHandler.Object, _mockFeedbackSender.Object, _mockClock.Object);

                controller.ControllerContext.HttpContext = new DefaultHttpContext();

                UbiUserIdHeaderHelper.AddUbiUserIdsToRequestHeader(
                    controller.ControllerContext.HttpContext.Request,
                    ubiUserId
                    );

                var responseResult = await controller.Post(requestBody);

                var response      = Assert.IsType <BadRequestObjectResult>(responseResult);
                var receivedError = Assert.IsAssignableFrom <Error>(response.Value);

                Assert.Equal(StatusCodes.Status400BadRequest, response.StatusCode);
                Assert.Equal(expectedError, receivedError);
            }