示例#1
0
        public PropertyBasedMethodMock(MocklisTypesForSymbols typesForSymbols, INamedTypeSymbol classSymbol, INamedTypeSymbol interfaceSymbol,
                                       IMethodSymbol symbol, string mockMemberName, bool strict, bool veryStrict) : base(typesForSymbols, classSymbol, interfaceSymbol, symbol,
                                                                                                                         mockMemberName, strict, veryStrict)
        {
            var parametersBuilder   = new SingleTypeOrValueTupleBuilder(TypesForSymbols);
            var returnValuesBuilder = new SingleTypeOrValueTupleBuilder(TypesForSymbols);

            if (!symbol.ReturnsVoid)
            {
                returnValuesBuilder.AddReturnValue(symbol.ReturnType, symbol.ReturnTypeIsNullableOrOblivious());
            }

            foreach (var parameter in symbol.Parameters)
            {
                switch (parameter.RefKind)
                {
                case RefKind.Ref:
                {
                    parametersBuilder.AddParameter(parameter);
                    returnValuesBuilder.AddParameter(parameter);
                    break;
                }

                case RefKind.Out:
                {
                    returnValuesBuilder.AddParameter(parameter);
                    break;
                }

                case RefKind.In:
                {
                    parametersBuilder.AddParameter(parameter);
                    break;
                }

                case RefKind.None:
                {
                    parametersBuilder.AddParameter(parameter);
                    break;
                }
                }
            }

            ParametersType   = parametersBuilder.Build();
            ReturnValuesType = returnValuesBuilder.Build();

            var parameterTypeSyntax = ParametersType.BuildTypeSyntax();

            var returnValueTypeSyntax = ReturnValuesType.BuildTypeSyntax();

            if (returnValueTypeSyntax == null)
            {
                MockMemberType = parameterTypeSyntax == null
                    ? TypesForSymbols.ActionMethodMock()
                    : TypesForSymbols.ActionMethodMock(parameterTypeSyntax);
            }
            else
            {
                MockMemberType = parameterTypeSyntax == null
                    ? TypesForSymbols.FuncMethodMock(returnValueTypeSyntax)
                    : TypesForSymbols.FuncMethodMock(parameterTypeSyntax, returnValueTypeSyntax);
            }
        }