public DataBundleResponseDto Parse(byte[] dataBundleReplyContract) { try { var bundleResponse = DataBundleResponseContract.Parser.ParseFrom(dataBundleReplyContract); var requestId = Guid.Parse(bundleResponse.RequestId); var requestIdempotency = bundleResponse.RequestIdempotencyId; if (bundleResponse.ReplyCase == DataBundleResponseContract.ReplyOneofCase.Success) { var successReply = bundleResponse.Success; return(new DataBundleResponseDto( requestId, requestIdempotency, new Uri(successReply.ContentUri))); } var failureReply = bundleResponse.Failure; var errorResponse = new DataBundleResponseErrorDto( MapToFailureReason(failureReply.Reason), failureReply.FailureDescription); return(new DataBundleResponseDto( requestId, requestIdempotency, errorResponse)); } catch (Exception ex) when(ex is InvalidProtocolBufferException or FormatException) { throw new MessageHubException("Error parsing bytes for DataBundleRequestDto", ex); } }
public void CreateErrorResponse_ReturnsResponse() { // arrange var requestId = Guid.Parse("BCDFAF35-B914-488E-A8FB-C41FC377097D"); var request = new DataBundleRequestDto( requestId, "CBF03641-95C2-4386-A04E-892CDF1D793A", "D5D400AD-CC11-409A-B757-75EB9AA8B0EA", new MessageTypeDto("message_type")); var dataBundleResponseErrorDto = new DataBundleResponseErrorDto( DataBundleResponseErrorReason.DatasetNotFound, "fake_description"); // act var actual = request.CreateErrorResponse(dataBundleResponseErrorDto); // assert Assert.Equal(requestId, actual.RequestId); Assert.Equal(dataBundleResponseErrorDto, actual.ResponseError); Assert.Equal(dataBundleResponseErrorDto.Reason, actual.ResponseError !.Reason); Assert.Equal(dataBundleResponseErrorDto.FailureDescription, actual.ResponseError.FailureDescription); }
/// <summary> /// Creates a failed <see cref="DataBundleResponseDto"/> from <see cref="DataBundleRequestDto"/>. /// </summary> /// <param name="request">The request to create a response from.</param> /// <param name="errorResponse">A description of the error.</param> /// <returns>The response to the specified request.</returns> public static DataBundleResponseDto CreateErrorResponse(this DataBundleRequestDto request, DataBundleResponseErrorDto errorResponse) { ArgumentNullException.ThrowIfNull(request, nameof(request)); return(new DataBundleResponseDto( request.RequestId, request.IdempotencyId, errorResponse)); }