예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
 public OperationDescription(string serviceName, string operationName, MessageAssembler message)
 {
     ServiceName                = serviceName;
     OperationName              = operationName;
     Message                    = message;
     GrpcMethodName             = "Method" + OperationName;
     GrpcMethodInputHeaderName  = "MethodHeader" + OperationName;
     GrpcMethodOutputHeaderName = "MethodOutputHeader" + OperationName;
 }
예제 #4
0
        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);
            }
        }
예제 #5
0
        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);
            }
        }
예제 #6
0
 // implemented only for unary calls
 public bool IsCompatibleWith(MessageAssembler other)
 {
     return(OperationType == other.OperationType &&
            RequestType == other.RequestType &&
            ResponseType == other.ResponseType);
 }
예제 #7
0
        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);
        }
예제 #8
0
        public void ContextInput(MethodInfo method, int[] expected)
        {
            var actual = new MessageAssembler(method).ContextInput;

            actual.ShouldBe(expected);
        }