Commit 69017a94 authored by Nathan Bean's avatar Nathan Bean
Browse files

Added support for functional validation

parent c74ed005
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Helpers\**" />
<EmbeddedResource Remove="Helpers\**" />
<None Remove="Helpers\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
......@@ -20,4 +27,8 @@
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.CodeRefactoring.Testing.MSTest" Version="1.0.1-beta1.*" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CodeAnalyzers\CodeAnalyzers.csproj" />
</ItemGroup>
</Project>
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Threading.Tasks;
using CodeAnalyzers.Test;
using KSU.CS.Pendant.CodeAnalyzers;
/*
namespace KSU.CS.Pendant.CodeAnalyzers.Test
{
[TestClass]
......@@ -41,3 +41,4 @@ namespace KSU.CS.Pendant.CodeAnalyzers.Test
}
}
}
*/
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using KSU.CS.Pendant;
using System.Threading.Tasks;
using KSU.CS.Pendant.CodeAnalysis.StyleAnalyzers;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Testing;
using CodeAnalyzers.Test;
using VerifyCS = CodeAnalyzers.Test.CSharpAnalyzerVerifier<
KSU.CS.Pendant.CodeAnalysis.StyleAnalyzers.CommentsAnalyzer>;
namespace KSU.CS.Pendant.CodeAnalyzers.Test
namespace KSU.CS.Pendant.CodeAnalysis.Test
{
[TestClass]
public class CommentsAnalyzerTests
public class CommentsAnalyzerTests
{
#region Class Commenting Tests
/// <summary>
/// Verifies whether the Comments Analyzer can detect proper XML commenting conventions on properties
/// </summary>
[TestMethod]
public async Task TestProperlyCommentedClass()
{
var test = @"
namespace ConsoleApplication1
{
/// <summary>
/// Sample Summary
/// </summary>
class Foo
{
}
}";
await CSharpAnalyzerVerifier<CommentsAnalyzer>.VerifyAnalyzerAsync(test);
}
/// <summary>
/// Verifies whether the Comments Analyzer can detect proper XML commenting conventions on properties
/// </summary>
[TestMethod]
public async Task TestClassMissingComments()
{
var test = @"
namespace ConsoleApplication1
{
{|#0:class Foo
{
}|}
}";
var expected = VerifyCS.Diagnostic("XMLC0001").WithLocation(0).WithArguments("Foo");
await CSharpAnalyzerVerifier<CommentsAnalyzer>.VerifyAnalyzerAsync(test, expected);
}
/// <summary>
/// Verifies whether the Comments Analyzer can detect proper XML commenting conventions on properties
/// </summary>
[TestMethod]
public async Task TestClassWithNoSummary()
{
var test = @"
namespace ConsoleApplication1
{
/// <remarks>
/// XML, but not a summary
/// </remarks>
{|#0:class Foo
{
}|}
}";
var expected = VerifyCS.Diagnostic("XMLC0001").WithLocation(0).WithArguments("Foo");
await CSharpAnalyzerVerifier<CommentsAnalyzer>.VerifyAnalyzerAsync(test, expected);
}
/// <summary>
/// Verifies whether the Comments Analyzer can detect proper XML commenting conventions on properties
/// </summary>
[TestMethod]
public async Task TestClassWithEmptySummary()
{
var test = @"
namespace ConsoleApplication1
{
/// <summary>
/// </summary>
{|#0:class Foo
{
}|}
}";
var expected = VerifyCS.Diagnostic("XMLC0001").WithLocation(0).WithArguments("Foo");
await CSharpAnalyzerVerifier<CommentsAnalyzer>.VerifyAnalyzerAsync(test, expected);
}
#endregion
#region Struct Commenting Tests
/// <summary>
/// Verifies whether the Comments Analyzer can detect proper XML commenting conventions on properties
/// </summary>
[TestMethod]
public async Task TestProperlyCommentedStruct()
{
var test = @"
namespace ConsoleApplication1
{
/// <summary>
/// Sample Summary
/// </summary>
struct Foo
{
}
}";
await CSharpAnalyzerVerifier<CommentsAnalyzer>.VerifyAnalyzerAsync(test);
}
/// <summary>
/// Verifies whether the Comments Analyzer can detect proper XML commenting conventions on properties
/// </summary>
[TestMethod]
public async Task TestStructMissingComments()
{
var test = @"
namespace ConsoleApplication1
{
{|#0:struct Foo
{
}|}
}";
var expected = VerifyCS.Diagnostic("XMLC0002").WithLocation(0).WithArguments("Foo");
await CSharpAnalyzerVerifier<CommentsAnalyzer>.VerifyAnalyzerAsync(test, expected);
}
/// <summary>
/// Verifies whether the Comments Analyzer can detect proper XML commenting conventions on properties
/// </summary>
[TestMethod]
public async Task TestStructWithNoSummary()
{
var test = @"
namespace ConsoleApplication1
{
/// <remarks>
/// XML, but not a summary
/// </remarks>
{|#0:struct Foo
{
}|}
}";
var expected = VerifyCS.Diagnostic("XMLC0002").WithLocation(0).WithArguments("Foo");
await CSharpAnalyzerVerifier<CommentsAnalyzer>.VerifyAnalyzerAsync(test, expected);
}
/// <summary>
/// Verifies whether the Comments Analyzer can detect proper XML commenting conventions on properties
/// </summary>
[TestMethod]
public async Task TestStructWithEmptySummary()
{
var test = @"
namespace ConsoleApplication1
{
/// <summary>
/// </summary>
{|#0:struct Foo
{
}|}
}";
var expected = VerifyCS.Diagnostic("XMLC0002").WithLocation(0).WithArguments("Foo");
await CSharpAnalyzerVerifier<CommentsAnalyzer>.VerifyAnalyzerAsync(test, expected);
}
#endregion
#region Interface Commenting Tests
/// <summary>
/// Verifies whether the Comments Analyzer can detect proper XML commenting conventions on properties
/// </summary>
[TestMethod]
public async Task TestProperlyCommentedInterface()
{
var test = @"
namespace ConsoleApplication1
{
/// <summary>
/// Sample Summary
/// </summary>
interface Foo
{
}
}";
await CSharpAnalyzerVerifier<CommentsAnalyzer>.VerifyAnalyzerAsync(test);
}
/// <summary>
/// Verifies whether the Comments Analyzer can detect proper XML commenting conventions on properties
/// </summary>
[TestMethod]
public async Task TestInterfaceMissingComments()
{
var test = @"
namespace ConsoleApplication1
{
{|#0:interface Foo
{
}|}
}";
var expected = VerifyCS.Diagnostic("XMLC0003").WithLocation(0).WithArguments("Foo");
await CSharpAnalyzerVerifier<CommentsAnalyzer>.VerifyAnalyzerAsync(test, expected);
}
/// <summary>
/// Verifies whether the Comments Analyzer can detect proper XML commenting conventions on properties
/// </summary>
[TestMethod]
public async Task TestInterfaceWithNoSummary()
{
var test = @"
namespace ConsoleApplication1
{
/// <remarks>
/// XML, but not a summary
/// </remarks>
{|#0:interface Foo
{
}|}
}";
var expected = VerifyCS.Diagnostic("XMLC0003").WithLocation(0).WithArguments("Foo");
await CSharpAnalyzerVerifier<CommentsAnalyzer>.VerifyAnalyzerAsync(test, expected);
}
/// <summary>
/// Verifies whether the Comments Analyzer can detect proper XML commenting conventions on properties
/// </summary>
[TestMethod]
public async Task TestInterfaceWithEmptySummary()
{
var test = @"
namespace ConsoleApplication1
{
/// <summary>
/// </summary>
{|#0:interface Foo
{
}|}
}";
var expected = VerifyCS.Diagnostic("XMLC0003").WithLocation(0).WithArguments("Foo");
await CSharpAnalyzerVerifier<CommentsAnalyzer>.VerifyAnalyzerAsync(test, expected);
}
#endregion
#region Interface Commenting Tests
/// <summary>
/// Verifies whether the Comments Analyzer can detect proper XML commenting conventions on properties
/// </summary>
[TestMethod]
public async Task TestProperlyCommentedEnum()
{
var test = @"
namespace ConsoleApplication1
{
/// <summary>
/// Sample Summary
/// </summary>
enum Foo
{
A, B, C
}
}";
await CSharpAnalyzerVerifier<CommentsAnalyzer>.VerifyAnalyzerAsync(test);
}
/// <summary>
/// Verifies whether the Comments Analyzer can detect proper XML commenting conventions on properties
/// </summary>
[TestMethod]
public async Task TestEnumMissingComments()
{
var test = @"
namespace ConsoleApplication1
{
{|#0:enum Foo
{
A, B, C
}|}
}";
var expected = VerifyCS.Diagnostic("XMLC0004").WithLocation(0).WithArguments("Foo");
await CSharpAnalyzerVerifier<CommentsAnalyzer>.VerifyAnalyzerAsync(test, expected);
}
/// <summary>
/// Verifies whether the Comments Analyzer can detect proper XML commenting conventions on properties
/// </summary>
[TestMethod]
public async Task TestEnumWithNoSummary()
{
var test = @"
namespace ConsoleApplication1
{
/// <remarks>
/// XML, but not a summary
/// </remarks>
{|#0:enum Foo
{
A, B, C
}|}
}";
var expected = VerifyCS.Diagnostic("XMLC0004").WithLocation(0).WithArguments("Foo");
await CSharpAnalyzerVerifier<CommentsAnalyzer>.VerifyAnalyzerAsync(test, expected);
}
/// <summary>
/// Verifies whether the Comments Analyzer can detect proper XML commenting conventions on properties
/// </summary>
[TestMethod]
public async Task TestEnumWithEmptySummary()
{
var test = @"
namespace ConsoleApplication1
{
/// <summary>
/// </summary>
{|#0:enum Foo
{
A, B, C
}|}
}";
var expected = VerifyCS.Diagnostic("XMLC0004").WithLocation(0).WithArguments("Foo");
await CSharpAnalyzerVerifier<CommentsAnalyzer>.VerifyAnalyzerAsync(test, expected);
}
#endregion
#region Field Commenting Tests
/// <summary>
/// Verifies whether the Comments Analyzer can detect proper XML commenting conventions on properties
/// </summary>
[TestMethod]
public async Task TestProperlyCommentedField()
{
var test = @"
namespace ConsoleApplication1
{
/// <summary>
/// Sample Summary
/// </summary>
class Foo
{
/// <summary>
/// Sample int
/// </summary>
public int bar = 3;
}
}";
await CSharpAnalyzerVerifier<CommentsAnalyzer>.VerifyAnalyzerAsync(test);
}
/// <summary>
/// Verifies whether the Comments Analyzer can detect proper XML commenting conventions on properties
/// </summary>
[TestMethod]
public async Task TestFieldMissingComments()
{
var test = @"
namespace ConsoleApplication1
{
/// <summary>
/// Sample Summary
/// </summary>
class Foo
{
{|#0:public int bar = 3;|}
}
}";
var expected = VerifyCS.Diagnostic("XMLC0005").WithLocation(0).WithArguments("bar");
await CSharpAnalyzerVerifier<CommentsAnalyzer>.VerifyAnalyzerAsync(test, expected);
}
/// <summary>
/// Verifies whether the Comments Analyzer can detect proper XML commenting conventions on properties
/// </summary>
[TestMethod]
public async Task TestFieldWithNoSummary()
{
var test = @"
namespace ConsoleApplication1
{
/// <summary>
/// Sample Summary
/// </summary>
class Foo
{
/// <remarks>
/// Remarks, but no summary
/// </remarks>
{|#0:public int bar = 3;|}
}
}";
var expected = VerifyCS.Diagnostic("XMLC0005").WithLocation(0).WithArguments("bar");
await CSharpAnalyzerVerifier<CommentsAnalyzer>.VerifyAnalyzerAsync(test, expected);
}
/// <summary>
/// Verifies whether the Comments Analyzer can detect proper XML commenting conventions on properties
/// </summary>
[TestMethod]
public async Task TestFieldWithEmptySummary()
{
var test = @"
namespace ConsoleApplication1
{
/// <summary>
/// Sample Summary
/// </summary>
class Foo
{
/// <summary>
///
/// </summary>
{|#0:public int bar = 3;|}
}
}";
var expected = VerifyCS.Diagnostic("XMLC0005").WithLocation(0).WithArguments("bar");
await CSharpAnalyzerVerifier<CommentsAnalyzer>.VerifyAnalyzerAsync(test, expected);
}
#endregion
#region Property Commenting Tests
/// <summary>
/// Verifies whether the Comments Analyzer can detect proper XML commenting conventions on properties
/// </summary>
[TestMethod]
public async Task TestProperlyCommentedProperty()
{
var test = @"
namespace ConsoleApplication1
{
/// <summary>
/// Sample Summary
/// </summary>
class Foo
{
/// <summary>
/// The bar is...
/// </summary>
int Bar { get; set; }
}
}";
await CSharpAnalyzerVerifier<CommentsAnalyzer>.VerifyAnalyzerAsync(test);
}
/// <summary>
/// Verifies whether the Comments Analyzer can detect proper XML commenting conventions on properties
/// </summary>
[TestMethod]
public async Task TestPropertyMissingComments()
{
var test = @"
namespace ConsoleApplication1
{
/// <summary>
/// Sample Summary
/// </summary>
class Foo
{
{|#0:int Bar { get; set; }|}
}
}";
var expected = VerifyCS.Diagnostic("XMLC0006").WithLocation(0).WithArguments("Bar");
await CSharpAnalyzerVerifier<CommentsAnalyzer>.VerifyAnalyzerAsync(test, expected);
}
/// <summary>
/// Verifies whether the Comments Analyzer can detect proper XML commenting conventions on properties
/// </summary>
[TestMethod]
public async Task TestPropertyWithNoSummary()
{
var test = @"
namespace ConsoleApplication1
{
/// <summary>
/// Sample Summary
/// </summary>
class Foo
{
/// <remark>
/// The bar is...
/// </remark>
{|#0:int Bar { get; set; }|}
}
}";
var expected = VerifyCS.Diagnostic("XMLC0006").WithLocation(0).WithArguments("Bar");
await CSharpAnalyzerVerifier<CommentsAnalyzer>.VerifyAnalyzerAsync(test, expected);
}
/// <summary>
/// Verifies whether the Comments Analyzer can detect proper XML commenting conventions on properties
/// </summary>
[TestMethod]
public async Task TestPropertyWithEmptySummary()
{
var test = @"
namespace ConsoleApplication1
{
/// <summary>
/// Sample Summary
/// </summary>
class Foo
{
/// <summary>
/// </summary>
{|#0:int Bar { get; set; }|}
}
}";
var expected = VerifyCS.Diagnostic("XMLC0006").WithLocation(0).WithArguments("Bar");
await CSharpAnalyzerVerifier<CommentsAnalyzer>.VerifyAnalyzerAsync(test, expected);
}
#endregion
#region Method Commenting Tests
/// <summary>
/// Verifies whether the Comments Analyzer can detect proper XML commenting conventions on properties
/// </summary>
[TestMethod]
public async Task TestProperlyCommentedMethodInClass()
{
var test = @"
namespace ConsoleApplication1
{
/// <summary>
/// Sample Summary
/// </summary>
class Foo
{
/// <summary>
/// The bar is...
/// </summary>