private static string GetBaseClassName(INamedTypeSymbol serviceType)
        {
            var result = new StringBuilder(serviceType.Name);

            if (result.Length > 0 && result[0] == 'I')
            {
                result.Remove(0, 1);
            }

            var serviceGenericEnding = ServiceContract.GetServiceGenericEnding(serviceType);

            for (var i = 0; i < serviceGenericEnding.Count; i++)
            {
                result.Append(serviceGenericEnding[i]);
            }

            for (var i = 0; i < result.Length; i++)
            {
                var c = result[i];
                if (c == '-' || c == '.' || c == '/' || c == '\\' || c == '`')
                {
                    result[i] = '_';
                }
            }

            return(result.ToString());
        }
Exemplo n.º 2
0
        public void RequestType(
            IMethodSymbol method,
            string requestClassName,
            int[] requestIndexes,
            string[] requestValueTypeName,
            string?headerClassName,
            int[] headerIndexes,
            string[]?headerValueTypeName)
        {
            var actual = new OperationDescription(method, "s1", ServiceContract.GetServiceOperationName(method));

            actual.RequestType.ClassName.ShouldBe(requestClassName);
            actual.RequestType.Properties.ShouldBe(requestValueTypeName);
            actual.RequestTypeInput.ShouldBe(requestIndexes);

            if (headerClassName == null)
            {
                actual.HeaderRequestType.ShouldBeNull();
                actual.HeaderRequestTypeInput.Length.ShouldBe(0);
            }
            else
            {
                actual.HeaderRequestType.ShouldNotBeNull();
                actual.HeaderRequestType.ClassName.ShouldBe(headerClassName);
                actual.HeaderRequestTypeInput.ShouldBe(headerIndexes);
                actual.HeaderRequestType.Properties.ShouldBe(headerValueTypeName);
            }
        }
Exemplo n.º 3
0
        public void GetServiceOperationName(Type type, string methodName, string expected)
        {
            var symbol = _compilation.GetTypeByMetadataName(type);

            symbol.ShouldNotBeNull();

            var method = SyntaxTools.GetInstanceMethods(symbol).First(i => i.Name == methodName);

            ServiceContract.GetServiceOperationName(method).ShouldBe(expected);
        }
        public OperationDescription(IMethodSymbol method, string serviceName)
        {
            ServiceName = serviceName;
            Method      = new MethodDescription(method);
            ValidateSignature();

            OperationName = ServiceContract.GetServiceOperationName(method);
            (ResponseType, ResponseTypeIndex, HeaderResponseType, HeaderResponseTypeInput) = CreateResponseType(method.ReturnType);
            (RequestType, RequestTypeInput, HeaderRequestType, HeaderRequestTypeInput)     = GetRequestType();
            OperationType              = GetOperationType();
            ContextInput               = GetContextInput();
            IsAsync                    = SyntaxTools.IsTask(method.ReturnType);
            GrpcMethodName             = "Method" + OperationName;
            GrpcMethodInputHeaderName  = "MethodInputHeader" + OperationName;
            GrpcMethodOutputHeaderName = "MethodOutputHeader" + OperationName;
        }
Exemplo n.º 5
0
        public void ResponseType(
            IMethodSymbol method,
            string className,
            string?valueTypeName,
            string?headerClassName,
            int[]?headerIndexes,
            string[]?headerValueTypeName,
            int?streamIndex)
        {
            var actual = new OperationDescription(method, "s1", ServiceContract.GetServiceOperationName(method));

            actual.ResponseType.ClassName.ShouldBe(className);
            if (valueTypeName == null)
            {
                actual.ResponseType.Properties.Length.ShouldBe(0);
            }
            else
            {
                actual.ResponseType.Properties.Length.ShouldBe(1);
                actual.ResponseType.Properties[0].ShouldBe(valueTypeName);
            }

            if (headerClassName == null)
            {
                actual.HeaderResponseType.ShouldBeNull();
                actual.HeaderResponseTypeInput.ShouldBeEmpty();
                actual.ResponseTypeIndex.ShouldBe(0);
            }
            else
            {
                actual.HeaderResponseType.ShouldNotBeNull();
                actual.HeaderResponseType.ClassName.ShouldBe(headerClassName);
                actual.HeaderResponseType.Properties.ShouldBe(headerValueTypeName);
                actual.HeaderResponseTypeInput.ShouldBe(headerIndexes);
                actual.ResponseTypeIndex.ShouldBe(streamIndex !.Value);
            }
        }
Exemplo n.º 6
0
        public void GetServiceName(Type type, string expected)
        {
            var symbol = _compilation.GetTypeByMetadataName(type);

            ServiceContract.GetServiceName(symbol).ShouldBe(expected);
        }
Exemplo n.º 7
0
        public void OperationType(IMethodSymbol method, MethodType expectedType)
        {
            var actual = new OperationDescription(method, "s1", ServiceContract.GetServiceOperationName(method));

            actual.OperationType.ShouldBe(expectedType);
        }
Exemplo n.º 8
0
        public void ContextInput(IMethodSymbol method, int[] indexes)
        {
            var actual = new OperationDescription(method, "s1", ServiceContract.GetServiceOperationName(method));

            actual.ContextInput.ShouldBe(indexes);
        }