Skip to content

Commit

Permalink
re-added the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
retailcoder committed Oct 10, 2019
1 parent bd672a0 commit 03c62ea
Show file tree
Hide file tree
Showing 2 changed files with 265 additions and 16 deletions.
16 changes: 8 additions & 8 deletions RubberduckCodeAnalysis/InspectionXmlDocAnalyzer.cs
Expand Up @@ -10,7 +10,7 @@ namespace RubberduckCodeAnalysis
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class InspectionXmlDocAnalyzer : DiagnosticAnalyzer
{
private const string MissingInspectionSummaryElement = "MissingInspectionSummaryTag";
public const string MissingInspectionSummaryElement = "MissingInspectionSummaryTag";
private static readonly DiagnosticDescriptor MissingSummaryTagRule = new DiagnosticDescriptor(
MissingInspectionSummaryElement,
new LocalizableResourceString(nameof(Resources.MissingInspectionSummaryTag), Resources.ResourceManager, typeof(Resources)),
Expand All @@ -21,7 +21,7 @@ public class InspectionXmlDocAnalyzer : DiagnosticAnalyzer
new LocalizableResourceString(nameof(Resources.MissingInspectionSummaryTagDescription), Resources.ResourceManager, typeof(Resources))
);

private const string MissingInspectionWhyElement = "MissingInspectionWhyTag";
public const string MissingInspectionWhyElement = "MissingInspectionWhyTag";
private static readonly DiagnosticDescriptor MissingWhyTagRule = new DiagnosticDescriptor(
MissingInspectionWhyElement,
new LocalizableResourceString(nameof(Resources.MissingInspectionWhyTag), Resources.ResourceManager, typeof(Resources)),
Expand All @@ -32,7 +32,7 @@ public class InspectionXmlDocAnalyzer : DiagnosticAnalyzer
new LocalizableResourceString(nameof(Resources.MissingInspectionWhyTagDescription), Resources.ResourceManager, typeof(Resources))
);

private const string MissingReferenceElement = "MissingReferenceTag";
public const string MissingReferenceElement = "MissingReferenceTag";
private static readonly DiagnosticDescriptor MissingReferenceTagRule = new DiagnosticDescriptor(
MissingReferenceElement,
new LocalizableResourceString(nameof(Resources.MissingInspectionReferenceTag), Resources.ResourceManager, typeof(Resources)),
Expand All @@ -43,7 +43,7 @@ public class InspectionXmlDocAnalyzer : DiagnosticAnalyzer
new LocalizableResourceString(nameof(Resources.MissingInspectionReferenceTagDescription), Resources.ResourceManager, typeof(Resources))
);

private const string MissingRequiredLibraryAttribute = "MissingRequiredLibraryAttribute";
public const string MissingRequiredLibraryAttribute = "MissingRequiredLibraryAttribute";
private static readonly DiagnosticDescriptor MissingRequiredLibAttributeRule = new DiagnosticDescriptor(
MissingRequiredLibraryAttribute,
new LocalizableResourceString(nameof(Resources.MissingRequiredLibAttribute), Resources.ResourceManager, typeof(Resources)),
Expand All @@ -54,7 +54,7 @@ public class InspectionXmlDocAnalyzer : DiagnosticAnalyzer
new LocalizableResourceString(nameof(Resources.MissingRequiredLibAttributeDescription), Resources.ResourceManager, typeof(Resources))
);

private const string MissingExampleElement = "MissingExampleTag";
public const string MissingExampleElement = "MissingExampleTag";
private static readonly DiagnosticDescriptor MissingExampleTagRule = new DiagnosticDescriptor(
MissingExampleElement,
new LocalizableResourceString(nameof(Resources.MissingExampleTag), Resources.ResourceManager, typeof(Resources)),
Expand All @@ -65,7 +65,7 @@ public class InspectionXmlDocAnalyzer : DiagnosticAnalyzer
new LocalizableResourceString(nameof(Resources.MissingExampleTagDescription), Resources.ResourceManager, typeof(Resources))
);

private const string MissingModuleElement = "MissingModuleTag";
public const string MissingModuleElement = "MissingModuleTag";
private static readonly DiagnosticDescriptor MissingModuleTagRule = new DiagnosticDescriptor(
MissingModuleElement,
new LocalizableResourceString(nameof(Resources.MissingModuleTag), Resources.ResourceManager, typeof(Resources)),
Expand All @@ -76,7 +76,7 @@ public class InspectionXmlDocAnalyzer : DiagnosticAnalyzer
new LocalizableResourceString(nameof(Resources.MissingModuleTagDescription), Resources.ResourceManager, typeof(Resources))
);

private const string MissingNameAttribute = "MissingNameAttribute";
public const string MissingNameAttribute = "MissingNameAttribute";
private static readonly DiagnosticDescriptor MissingNameAttributeRule = new DiagnosticDescriptor(
MissingNameAttribute,
new LocalizableResourceString(nameof(Resources.MissingNameAttribute), Resources.ResourceManager, typeof(Resources)),
Expand All @@ -87,7 +87,7 @@ public class InspectionXmlDocAnalyzer : DiagnosticAnalyzer
new LocalizableResourceString(nameof(Resources.MissingNameAttributeDescription), Resources.ResourceManager, typeof(Resources))
);

private const string MissingHasResultAttribute = "MissingHasResultAttribute";
public const string MissingHasResultAttribute = "MissingHasResultAttribute";
private static readonly DiagnosticDescriptor MissingHasResultAttributeRule = new DiagnosticDescriptor(
MissingNameAttribute,
new LocalizableResourceString(nameof(Resources.MissingHasResultAttribute), Resources.ResourceManager, typeof(Resources)),
Expand Down
265 changes: 257 additions & 8 deletions RubberduckTestsCodeAnalysis/InspectionXmlDocAnalyzerTests.cs
@@ -1,12 +1,261 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using NUnit.Framework;
using TestHelper;

namespace RubberduckTestsCodeAnalysis
namespace RubberduckCodeAnalysis.Test
{
class InspectionXmlDocAnalyzerTests
[TestFixture]
public class InspectionXmlDocAnalyzerTests : DiagnosticVerifier
{
}
protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
=> new InspectionXmlDocAnalyzer();

private Diagnostic[] GetDiagnostics(string code)
{
const string iinspection = @"
public interface IInspection { }
";
return GetSortedDiagnostics(new[] { iinspection + code }, LanguageNames.CSharp, GetCSharpDiagnosticAnalyzer());
}

[Test][Category("InspectionXmlDoc")]
public void NegativeIfNotInNamespaceRubberduckCodeAnalysisInspectionConcrete()
{
var test = @"
namespace Rubberduck.CodeAnalysis.Inspections.NotConcrete
{
/// <summary>
/// blablabla
/// </summary>
/// <why>
/// blablabla
/// </why>
/// <example hasresult=""true"">
/// <![CDATA[
/// Public Sub DoSomething()
/// ' ...
/// End Sub
/// ]]>
/// </example>
public sealed class SomeInspection : IInspection { }
}
";

var diagnostics = GetDiagnostics(test);
Assert.IsFalse(diagnostics.Any(d => d.Descriptor.Id == InspectionXmlDocAnalyzer.MissingInspectionSummaryElement));
}

[Test][Category("InspectionXmlDoc")]
public void NegativeIfNotInInheritingIInspection()
{
var test = @"
namespace Rubberduck.CodeAnalysis.Inspections.Abstract
{
/// <summary>
/// blablabla
/// </summary>
/// <why>
/// blablabla
/// </why>
/// <example hasresult=""true"">
/// <![CDATA[
/// Public Sub DoSomething()
/// ' ...
/// End Sub
/// ]]>
/// </example>
public sealed class SomeInspection : NotIInspection { }
}
";

var diagnostics = GetDiagnostics(test);
Assert.IsFalse(diagnostics.Any(d => d.Descriptor.Id == InspectionXmlDocAnalyzer.MissingInspectionSummaryElement));
}

[Test][Category("InspectionXmlDoc")]
public void MissingInspectionSummary_Negative()
{
var test = @"
namespace Rubberduck.CodeAnalysis.Inspections.Concrete
{
/// <summary>
/// blablabla
/// </summary>
/// <why>
/// blablabla
/// </why>
/// <example hasresult=""true"">
/// <![CDATA[
/// Public Sub DoSomething()
/// ' ...
/// End Sub
/// ]]>
/// </example>
public sealed class SomeInspection : IInspection { }
}
";

var diagnostics = GetDiagnostics(test);
Assert.IsFalse(diagnostics.Any(d => d.Descriptor.Id == InspectionXmlDocAnalyzer.MissingInspectionSummaryElement));
}

[Test][Category("InspectionXmlDoc")]
public void MissingInspectionSummary()
{
var test = @"
namespace Rubberduck.CodeAnalysis.Inspections.Concrete
{
/// <why>
/// blablabla
/// </why>
/// <example hasresult=""true"">
/// <![CDATA[
/// Public Sub DoSomething()
/// ' ...
/// End Sub
/// ]]>
/// </example>
public sealed class SomeInspection : IInspection { }
}
";

var diagnostics = GetDiagnostics(test);
Assert.IsTrue(diagnostics.Any(d => d.Descriptor.Id == InspectionXmlDocAnalyzer.MissingInspectionSummaryElement));
}


[Test][Category("InspectionXmlDoc")]
public void MissingInspectionWhyElement()
{
var test = @"
namespace Rubberduck.CodeAnalysis.Inspections.Concrete
{
/// <summary>
/// blablabla
/// </summary>
/// <example hasresult=""true"">
/// <![CDATA[
/// Public Sub DoSomething()
/// ' ...
/// End Sub
/// ]]>
/// </example>
public sealed class SomeInspection : IInspection { }
}
";

var diagnostics = GetDiagnostics(test);
Assert.IsTrue(diagnostics.Any(d => d.Descriptor.Id == InspectionXmlDocAnalyzer.MissingInspectionWhyElement));
}

[Test][Category("InspectionXmlDoc")]
public void MissingInspectionWhyElement_Negative()
{
var test = @"
namespace Rubberduck.CodeAnalysis.Inspections.Concrete
{
/// <summary>
/// blablabla
/// </summary>
/// <why>
/// blablabla
/// </why>
/// <example hasresult=""true"">
/// <![CDATA[
/// Public Sub DoSomething()
/// ' ...
/// End Sub
/// ]]>
/// </example>
public sealed class SomeInspection : IInspection { }
}
";

var diagnostics = GetDiagnostics(test);
Assert.IsFalse(diagnostics.Any(d => d.Descriptor.Id == InspectionXmlDocAnalyzer.MissingInspectionWhyElement));
}

[Test][Category("InspectionXmlDoc")]
public void MissingHasResultAttribute_Misspelled()
{
var test = @"
namespace Rubberduck.CodeAnalysis.Inspections.Concrete
{
/// <summary>
/// blablabla
/// </summary>
/// <why>
/// blablabla
/// </why>
/// <example hasResults=""true"">
/// <![CDATA[
/// Public Sub DoSomething()
/// ' ...
/// End Sub
/// ]]>
/// </example>
public sealed class SomeInspection : IInspection { }
}
";

var diagnostics = GetDiagnostics(test);
Assert.IsTrue(diagnostics.Any(d => d.Descriptor.Id == InspectionXmlDocAnalyzer.MissingHasResultAttribute));
}

[Test][Category("InspectionXmlDoc")]
public void MissingHasResultAttribute_Missing()
{
var test = @"
namespace Rubberduck.CodeAnalysis.Inspections.Concrete
{
/// <summary>
/// blablabla
/// </summary>
/// <why>
/// blablabla
/// </why>
/// <example>
/// <![CDATA[
/// Public Sub DoSomething()
/// ' ...
/// End Sub
/// ]]>
/// </example>
public sealed class SomeInspection : IInspection { }
}
";

var diagnostics = GetDiagnostics(test);
Assert.IsTrue(diagnostics.Any(d => d.Descriptor.Id == InspectionXmlDocAnalyzer.MissingHasResultAttribute));
}

[Test][Category("InspectionXmlDoc")]
public void MissingHasResultAttribute_Negative()
{
var test = @"
namespace Rubberduck.CodeAnalysis.Inspections.Concrete
{
/// <summary>
/// blablabla
/// </summary>
/// <why>
/// blablabla
/// </why>
/// <example hasresult=""true"">
/// <![CDATA[
/// Public Sub DoSomething()
/// ' ...
/// End Sub
/// ]]>
/// </example>
public sealed class SomeInspection : IInspection { }
}
";

var diagnostics = GetDiagnostics(test);
Assert.IsFalse(diagnostics.Any(d => d.Descriptor.Id == InspectionXmlDocAnalyzer.MissingHasResultAttribute));
}
}
}

0 comments on commit 03c62ea

Please sign in to comment.