Ejemplo n.º 1
0
        public static bool IsApiControllerAction(ApiControllerSymbolCache symbolCache, IMethodSymbol method)
        {
            if (method == null)
            {
                return(false);
            }

            if (method.ReturnsVoid || method.ReturnType.TypeKind == TypeKind.Error)
            {
                return(false);
            }

            if (!MvcFacts.IsController(method.ContainingType, symbolCache.ControllerAttribute, symbolCache.NonControllerAttribute))
            {
                return(false);
            }

            if (!method.ContainingType.HasAttribute(symbolCache.IApiBehaviorMetadata, inherit: true))
            {
                return(false);
            }

            if (!MvcFacts.IsControllerAction(method, symbolCache.NonActionAttribute, symbolCache.IDisposableDispose))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        private async Task IsControllerReturnsTrue(Type type)
        {
            var compilation = await GetIsControllerCompilation();

            var controllerAttribute    = compilation.GetTypeByMetadataName(ControllerAttribute);
            var nonControllerAttribute = compilation.GetTypeByMetadataName(NonControllerAttribute);
            var typeSymbol             = compilation.GetTypeByMetadataName(type.FullName);

            // Act
            var isController = MvcFacts.IsController(typeSymbol, controllerAttribute, nonControllerAttribute);

            // Assert
            Assert.True(isController);
        }