public void CreateDocumentId_By_CombiningSessionIdAndPlayerId() { var playerFeedbackDto = new PlayerFeedbackDto { SessionId = new Guid("1e4b4f69-472d-4190-bdb2-450e8ae6e36d"), PlayerId = "player-id-1", Rating = 5, Comment = "", Timestamp = new DateTime(2021, 3, 15) }; var document = PlayerFeedbackDocument.CreateFromDto(playerFeedbackDto); var expectedDoc = new PlayerFeedbackDocument { Id = $"{playerFeedbackDto.SessionId.ToString()}-{playerFeedbackDto.PlayerId.ToString()}", SessionId = playerFeedbackDto.SessionId, PlayerId = playerFeedbackDto.PlayerId, Rating = playerFeedbackDto.Rating, Comment = playerFeedbackDto.Comment, Timestamp = playerFeedbackDto.Timestamp }; Assert.Equal(expectedDoc, document); }
public SendShould() { _playerFeedback = new PlayerFeedbackDto { SessionId = new Guid("1e4b4f69-472d-4190-bdb2-450e8ae6e36d"), PlayerId = "player-id-1", Rating = 5, Comment = "", Timestamp = new DateTime(2021, 3, 12) }; }
public async Task Store(PlayerFeedbackDto feedback) { var feedbackDocument = PlayerFeedbackDocument.CreateFromDto(feedback); var creationResult = await _elasticClient.CreateDocumentAsync(feedbackDocument); if (creationResult.IsValid) { return; } if (creationResult.ServerError.Error.Type == ElasticsearchError.DocumentVersionConflictError) { throw DuplicateFeedbackException.Create(feedback.SessionId, feedback.PlayerId, feedback.Timestamp); } var unexpectedError = ElasticsearchError.GenerateMessageForPlayerFeedbackInsertionError(feedback); throw new UnexpectedFeedbackInsertionException(unexpectedError, creationResult.OriginalException); }
public async Task <Result> Send(PlayerFeedbackDto feedback) { var feedbackValidation = PlayerFeedback.Create( feedback.SessionId, feedback.PlayerId, feedback.Rating, feedback.Comment, feedback.Timestamp ); if (!feedbackValidation.IsOk) { return(Result.Fail(feedbackValidation.Error)); } await _messageSender.Send(AddPlayerFeedbackMessage.CreateFromDomain(feedbackValidation.Value)); return(Result.Ok()); }
public static string GenerateMessageForPlayerFeedbackInsertionError(PlayerFeedbackDto feedback) { var serializedFeedback = JsonSerializer.Serialize(feedback); return($"Failed to insert PlayerFeedback: {serializedFeedback}"); }