public async Task InspectReturnExpression_ReturnsNull_ForReturnTypeIf201StatusCodeIsDeclared()
        {
            // Arrange
            var compilation = await GetCompilation();

            var returnType = compilation.GetTypeByMetadataName(typeof(ApiConventionAnalyzerBaseModel).FullName);
            var context    = GetContext(compilation, new[] { 201 });

            // Act
            var diagnostic = ApiConventionAnalyzer.InspectReturnExpression(context, returnType, Location.None);

            // Assert
            Assert.Null(diagnostic);
        }
        public async Task InspectReturnExpression_DoesNotReturnDiagnostic_IfReturnTypeDoesNotHaveStatusCodeAttribute()
        {
            // Arrange
            var compilation = await GetCompilation();

            var context          = GetContext(compilation, new[] { 200, 404 });
            var actualReturnType = compilation.GetTypeByMetadataName(typeof(EmptyResult).FullName);

            // Act
            var diagnostic = ApiConventionAnalyzer.InspectReturnExpression(context, actualReturnType, Location.None);

            // Assert
            Assert.Null(diagnostic);
        }
        public async Task InspectReturnExpression_DoesNotReturnDiagnostic_IfDeclaredAndActualReturnTypeAreIActionResult()
        {
            // Arrange
            var compilation = await GetCompilation();

            var context          = GetContext(compilation, new[] { 404 });
            var actualReturnType = compilation.GetTypeByMetadataName(typeof(IActionResult).FullName);

            // Act
            var diagnostic = ApiConventionAnalyzer.InspectReturnExpression(context, actualReturnType, Location.None);

            // Assert
            Assert.Null(diagnostic);
        }
        public async Task InspectReturnExpression_ReturnsDiagnostic_If200IsNotDocumented()
        {
            // Arrange
            var compilation = await GetCompilation();

            var context          = GetContext(compilation, new[] { 404 });
            var actualReturnType = compilation.GetTypeByMetadataName(typeof(ApiConventionAnalyzerDerivedModel).FullName);

            // Act
            var diagnostic = ApiConventionAnalyzer.InspectReturnExpression(context, actualReturnType, Location.None);

            // Assert
            Assert.NotNull(diagnostic);
            Assert.Same(DiagnosticDescriptors.MVC1005_ActionReturnsUndocumentedSuccessResult, diagnostic.Descriptor);
        }
        public async Task InspectReturnExpression_ReturnsDiagnostic_IfReturnTypeIsActionResultReturningUndocumentedStatusCode()
        {
            // Arrange
            var compilation = await GetCompilation();

            var declaredReturnType = compilation.GetTypeByMetadataName(typeof(ApiConventionAnalyzerBaseModel).FullName);
            var context            = GetContext(compilation, new[] { 200, 404 });
            var actualReturnType   = compilation.GetTypeByMetadataName(typeof(BadRequestObjectResult).FullName);

            // Act
            var diagnostic = ApiConventionAnalyzer.InspectReturnExpression(context, actualReturnType, Location.None);

            // Assert
            Assert.NotNull(diagnostic);
            Assert.Same(DiagnosticDescriptors.MVC1004_ActionReturnsUndocumentedStatusCode, diagnostic.Descriptor);
        }