Example #1
0
        public static InjectableType TryCreateInjectableTypeFromParameterNode(SyntaxNode parameterNode, SemanticModel semanticModel, MockFramework mockFramework)
        {
            SyntaxNode node     = parameterNode.ChildNodes().FirstOrDefault();
            SyntaxKind nodeKind = node.Kind();

            if (nodeKind != SyntaxKind.IdentifierName && nodeKind != SyntaxKind.GenericName)
            {
                return(null);
            }

            if (nodeKind == SyntaxKind.GenericName && !MockFrameworkAbstraction.SupportsGenerics(mockFramework))
            {
                return(null);
            }

            SymbolInfo symbolInfo  = semanticModel.GetSymbolInfo(node);
            var        namedSymbol = symbolInfo.Symbol as INamedTypeSymbol;

            if (namedSymbol != null && !namedSymbol.IsReferenceType)
            {
                // We can only mock reference types
                return(null);
            }

            return(CreateInjectableType(node, semanticModel, symbolInfo));
        }
        public static InjectableProperty TryCreateInjectableProperty(string propertyName, string fullTypeString, MockFramework mockFramework)
        {
            if (!MockFrameworkAbstraction.SupportsGenerics(mockFramework) && fullTypeString.Contains("<"))
            {
                return(null);
            }

            return(new InjectableProperty(propertyName, fullTypeString));
        }