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_WhenHeaderIsNotPresent()
            {
                var httpContext = new DefaultHttpContext();

                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);
            }
        public async Task <IActionResult> Post([FromBody] PlayerFeedBackRequest feedback)
        {
            var ubiUserIdExtractionResult = UbiUserIdHeader.ExtractUbiUserId(Request);

            if (ubiUserIdExtractionResult.IsError)
            {
                return(BadRequest(ubiUserIdExtractionResult.Error));
            }

            var utcTimeNow = _clock.GetTimeNow();

            var feedbackSendingResult =
                await _feedbackSender.Send(feedback.ToDto(utcTimeNow, ubiUserIdExtractionResult.Value));

            if (feedbackSendingResult.IsOk)
            {
                return(Ok());
            }

            return(BadRequest(feedbackSendingResult.Error));
        }