コード例 #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);
        }
コード例 #2
0
ファイル: MvcFactsTest.cs プロジェクト: sumitmudkondwar/Mvc
        private async Task IsActionReturnsTrue(Type type, string methodName)
        {
            var compilation = await GetIsControllerActionCompilation();

            var nonActionAttribute = compilation.GetTypeByMetadataName(NonActionAttribute);
            var disposableDispose  = GetDisposableDispose(compilation);
            var typeSymbol         = compilation.GetTypeByMetadataName(type.FullName);
            var method             = (IMethodSymbol)typeSymbol.GetMembers(methodName).First();

            // Act
            var isControllerAction = MvcFacts.IsControllerAction(method, nonActionAttribute, disposableDispose);

            // Assert
            Assert.True(isControllerAction);
        }
コード例 #3
0
ファイル: MvcFactsTest.cs プロジェクト: sumitmudkondwar/Mvc
        public async Task IsAction_ReturnsTrueForNotDisposableDisposeOnTypeWithImplicitImplementation()
        {
            var compilation = await GetIsControllerActionCompilation();

            var nonActionAttribute = compilation.GetTypeByMetadataName(NonActionAttribute);
            var disposableDispose  = GetDisposableDispose(compilation);
            var typeSymbol         = compilation.GetTypeByMetadataName(typeof(NotDisposableWithDisposeThatIsNotInterfaceContract).FullName);
            var method             = typeSymbol.GetMembers(nameof(IDisposable.Dispose)).OfType <IMethodSymbol>().First(f => !f.ReturnsVoid);

            // Act
            var isControllerAction = MvcFacts.IsControllerAction(method, nonActionAttribute, disposableDispose);

            // Assert
            Assert.True(isControllerAction);
        }