private static bool TryCreateMessage(MethodInfo method, [MaybeNullWhen(false)] out MessageAssembler message, [MaybeNullWhen(true)] out string error) { message = default; error = default; try { message = new MessageAssembler(method); return(true); } catch (NotSupportedException ex) { var text = new StringBuilder(); Exception?e = ex; while (e != null) { if (text.Length > 0) { text.Append(" --> "); } text.Append(ex.Message); e = e.InnerException; } error = text.ToString(); return(false); } }
public void IsCompatibleWith(MethodInfo method, MethodInfo other, bool expected) { var sut = new MessageAssembler(method); var otherSut = new MessageAssembler(other); sut.IsCompatibleWith(otherSut).ShouldBe(expected); otherSut.IsCompatibleWith(sut).ShouldBe(expected); }
public OperationDescription(string serviceName, string operationName, MessageAssembler message) { ServiceName = serviceName; OperationName = operationName; Message = message; GrpcMethodName = "Method" + OperationName; GrpcMethodInputHeaderName = "MethodHeader" + OperationName; GrpcMethodOutputHeaderName = "MethodOutputHeader" + OperationName; }
public void RequestType( MethodInfo method, Type requestType, int[] requestIndexes, Type?headerRequestType, int[] headerIndexes) { var sut = new MessageAssembler(method); sut.RequestType.ShouldBe(requestType); sut.RequestTypeInput.ShouldBe(requestIndexes); sut.HeaderRequestType.ShouldBe(headerRequestType); if (headerRequestType == null) { sut.HeaderRequestTypeInput.ShouldBeEmpty(); } else { sut.HeaderRequestTypeInput.ShouldBe(headerIndexes); } }
public void ResponseType( MethodInfo method, Type responseType, Type?headerResponseType, int[]?headerIndexes, int?streamIndex) { var actual = new MessageAssembler(method); actual.ResponseType.ShouldBe(responseType); actual.HeaderResponseType.ShouldBe(headerResponseType); if (headerResponseType == null) { actual.HeaderResponseTypeInput.ShouldBeEmpty(); actual.ResponseTypeIndex.ShouldBe(0); } else { actual.HeaderResponseTypeInput.ShouldBe(headerIndexes); actual.ResponseTypeIndex.ShouldBe(streamIndex !.Value); } }
// implemented only for unary calls public bool IsCompatibleWith(MessageAssembler other) { return(OperationType == other.OperationType && RequestType == other.RequestType && ResponseType == other.ResponseType); }
private static OperationDescription?TryFindAsyncOperation(IList <OperationDescription> operations, MessageAssembler syncOperation) { var asyncMethodName = syncOperation.Operation.Name + "Async"; for (var i = 0; i < operations.Count; i++) { var operation = operations[i]; if (operation.Message.IsAsync && operation.Message.OperationType == MethodType.Unary && operation.Message.Operation.Name.Equals(asyncMethodName, StringComparison.OrdinalIgnoreCase) && operation.Message.IsCompatibleWith(syncOperation)) { return(operation); } } return(null); }
public void ContextInput(MethodInfo method, int[] expected) { var actual = new MessageAssembler(method).ContextInput; actual.ShouldBe(expected); }