Skip to content

Commit

Permalink
Fast fix - Fix tests to be possible pass GitHub checks (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter M authored Apr 21, 2019
1 parent 0a3e62a commit 305a756
Show file tree
Hide file tree
Showing 28 changed files with 106 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
using MalikP.Analyzers.AsyncMethodAnalyzer.Analyzers.Specific;
using MalikP.Analyzers.AsyncMethodAnalyzer.Analyzers.Specific.Naming;
using MalikP.Analyzers.AsyncMethodAnalyzer.CodeFixes.Specific;
using MalikP.Analyzers.AsyncMethodAnalyzer.Rules.Naming;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Diagnostics;
Expand All @@ -39,11 +40,11 @@
namespace MalikP.Analyzers.AsyncMethodAnalyzer.Test
{
[TestClass]
public class UnitTest : CodeFixVerifier
public class AddMissingAsyncSuffix_Declaration_Task_Test : CodeFixVerifier
{
//No diagnostics expected to show up
[TestMethod]
public void TestMethod1()
public void VeryfyNoDiagnosticWillShowUp_AddMissingAsyncSuffix_Declaration()
{
var test = @"";

Expand All @@ -52,30 +53,37 @@ public void TestMethod1()

//Diagnostic and CodeFix both triggered and checked for
[TestMethod]
public void TestMethod2()
public void VerifyTaskMethodAsyncSuffix()
{
var test = @"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics;
namespace ConsoleApplication1
{
class TypeName
{
public Task MyTask()
{
return Task.Delay(1);
}
}
}";
var rule = MethodMissingAsyncSuffix_Task_Declaration_Rule.Rule;

var expected = new DiagnosticResult
{
Id = "AsyncMethodAnalyzer",
Message = String.Format("Type name '{0}' contains lowercase letters", "TypeName"),
Severity = DiagnosticSeverity.Warning,
Id = "AANA001",
Message = String.Format(rule.MessageFormat.ToString(), "MyTask"),
Severity = rule.DefaultSeverity,
Locations =
new[] {
new DiagnosticResultLocation("Test0.cs", 11, 15)
new DiagnosticResultLocation("Test0.cs", 14, 25)
}
};

Expand All @@ -86,13 +94,18 @@ class TypeName
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics;
namespace ConsoleApplication1
{
class TYPENAME
class TypeName
{
public Task MyTaskAsync()
{
return Task.Delay(1);
}
}
}";
VerifyCSharpFix(test, fixtest);
Expand All @@ -105,7 +118,7 @@ protected override CodeFixProvider GetCSharpCodeFixProvider()

protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
{
return new CancellationTokenNameAnalyzer();
return new AsyncMethodNameSuffix_Task_Declaration_Analyzer();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
using MalikP.Analyzers.AsyncMethodAnalyzer.Analyzers.Specific;
using MalikP.Analyzers.AsyncMethodAnalyzer.Analyzers.Specific.Naming;
using MalikP.Analyzers.AsyncMethodAnalyzer.CodeFixes.Specific;
using MalikP.Analyzers.AsyncMethodAnalyzer.Rules.Naming;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Diagnostics;
Expand All @@ -39,11 +40,11 @@
namespace MalikP.Analyzers.AsyncMethodAnalyzer.Test
{
[TestClass]
public class UnitTest : CodeFixVerifier
public class AddMissingAsyncSuffix_Declaration_Task_Test : CodeFixVerifier
{
//No diagnostics expected to show up
[TestMethod]
public void TestMethod1()
public void VeryfyNoDiagnosticWillShowUp_AddMissingAsyncSuffix_Declaration()
{
var test = @"";

Expand All @@ -52,30 +53,37 @@ public void TestMethod1()

//Diagnostic and CodeFix both triggered and checked for
[TestMethod]
public void TestMethod2()
public void VerifyTaskMethodAsyncSuffix()
{
var test = @"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics;
namespace ConsoleApplication1
{
class TypeName
{
public Task MyTask()
{
return Task.Delay(1);
}
}
}";
var rule = MethodMissingAsyncSuffix_Task_Declaration_Rule.Rule;

var expected = new DiagnosticResult
{
Id = "AsyncMethodAnalyzer",
Message = String.Format("Type name '{0}' contains lowercase letters", "TypeName"),
Severity = DiagnosticSeverity.Warning,
Id = "AANA001",
Message = String.Format(rule.MessageFormat.ToString(), "MyTask"),
Severity = rule.DefaultSeverity,
Locations =
new[] {
new DiagnosticResultLocation("Test0.cs", 11, 15)
new DiagnosticResultLocation("Test0.cs", 14, 25)
}
};

Expand All @@ -86,13 +94,18 @@ class TypeName
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics;
namespace ConsoleApplication1
{
class TYPENAME
class TypeName
{
public Task MyTaskAsync()
{
return Task.Delay(1);
}
}
}";
VerifyCSharpFix(test, fixtest);
Expand All @@ -105,7 +118,7 @@ protected override CodeFixProvider GetCSharpCodeFixProvider()

protected override DiagnosticAnalyzer GetCSharpDiagnosticAnalyzer()
{
return new CancellationTokenNameAnalyzer();
return new AsyncMethodNameSuffix_Task_Declaration_Analyzer();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
// SOFTWARE.

using System.Collections.Immutable;
using System.Text;

using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System;
using System.Linq;

using MalikP.Analyzers.AsyncMethodAnalyzer.Rules.Design;
Expand All @@ -36,7 +35,7 @@
namespace MalikP.Analyzers.AsyncMethodAnalyzer.Analyzers.Specific.Design
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class CancellationTokenParameterExistence_Declaration_Analyzer : Abstract_Method_SymbolActionDiagnosticAnalyze
public sealed class CancellationTokenParameterExistence_Declaration_Analyzer : Abstract_Method_SymbolActionDiagnosticAnalyze
{
private const string _genericTaskType = "System.Threading.Tasks.Task<TResult>";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System;
using System.Linq;

using MalikP.Analyzers.AsyncMethodAnalyzer.Rules.Design;
Expand All @@ -36,7 +35,7 @@
namespace MalikP.Analyzers.AsyncMethodAnalyzer.Analyzers.Specific.Design
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class CancellationTokenParameterExistence_Task_Invocation_Analyzer : Abstract_InvocationExpressionSyntax_SyntaxNodeActionDiagnosticAnalyzer
public sealed class CancellationTokenParameterExistence_Task_Invocation_Analyzer : Abstract_InvocationExpressionSyntax_SyntaxNodeActionDiagnosticAnalyzer
{
private const string _genericTaskType = "System.Threading.Tasks.Task<TResult>";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
namespace MalikP.Analyzers.AsyncMethodAnalyzer.Analyzers.Specific.Design
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class CancellationTokenParameterExistence_Void_Declaration_Analyzer : Abstract_Method_SymbolActionDiagnosticAnalyze
public sealed class CancellationTokenParameterExistence_Void_Declaration_Analyzer : Abstract_Method_SymbolActionDiagnosticAnalyze
{
protected override DiagnosticDescriptor DiagnosticDescriptor => MissingCancellationTokenParameter_Void_Declaration_Rule.Rule;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
namespace MalikP.Analyzers.AsyncMethodAnalyzer.Analyzers.Specific.Design
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class CancellationTokenParameterExistence_Void_Invocation_Analyzer : Abstract_InvocationExpressionSyntax_SyntaxNodeActionDiagnosticAnalyzer
public sealed class CancellationTokenParameterExistence_Void_Invocation_Analyzer : Abstract_InvocationExpressionSyntax_SyntaxNodeActionDiagnosticAnalyzer
{
protected override DiagnosticDescriptor DiagnosticDescriptor => MissingCancellationTokenParameter_Void_Invocation_Rule.Rule;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
namespace MalikP.Analyzers.AsyncMethodAnalyzer.Analyzers.Specific.Design
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class CancellationTokenParameterPositionAnalyzer : Abstract_Method_SymbolActionDiagnosticAnalyze
public sealed class CancellationTokenParameterPositionAnalyzer : Abstract_Method_SymbolActionDiagnosticAnalyze
{
protected override DiagnosticDescriptor DiagnosticDescriptor => WrongCancellationTokenMethodParameterPosition_Declaration_Rule.Rule;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System;
using System.Linq;

using MalikP.Analyzers.AsyncMethodAnalyzer.Rules.Design;
Expand All @@ -36,7 +35,7 @@
namespace MalikP.Analyzers.AsyncMethodAnalyzer.Analyzers.Specific.Design
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class CancellationTokenParameterReusePossibility_Task_Invocation_Analyzer : Abstract_InvocationExpressionSyntax_SyntaxNodeActionDiagnosticAnalyzer
public sealed class CancellationTokenParameterReusePossibility_Task_Invocation_Analyzer : Abstract_InvocationExpressionSyntax_SyntaxNodeActionDiagnosticAnalyzer
{
private const string _genericTaskType = "System.Threading.Tasks.Task<TResult>";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
namespace MalikP.Analyzers.AsyncMethodAnalyzer.Analyzers.Specific.Design
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class CancellationTokenParameterReusePossibility_Void_Invocation_Analyzer : Abstract_InvocationExpressionSyntax_SyntaxNodeActionDiagnosticAnalyzer
public sealed class CancellationTokenParameterReusePossibility_Void_Invocation_Analyzer : Abstract_InvocationExpressionSyntax_SyntaxNodeActionDiagnosticAnalyzer
{
protected override DiagnosticDescriptor DiagnosticDescriptor => CancellationTokenParameterReusePossibility_Void_Invocation_Rule.Rule;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System;

using MalikP.Analyzers.AsyncMethodAnalyzer.Rules.Naming;

Expand All @@ -35,7 +34,7 @@
namespace MalikP.Analyzers.AsyncMethodAnalyzer.Analyzers.Specific.Naming
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class AsyncMethodNameSuffix_Task_Declaration_Analyzer : Abstract_Method_SymbolActionDiagnosticAnalyze
public sealed class AsyncMethodNameSuffix_Task_Declaration_Analyzer : Abstract_Method_SymbolActionDiagnosticAnalyze
{
private const string _genericTaskType = "System.Threading.Tasks.Task<TResult>";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System;

using MalikP.Analyzers.AsyncMethodAnalyzer.Rules.Naming;

using Microsoft.CodeAnalysis;
Expand All @@ -35,7 +33,7 @@
namespace MalikP.Analyzers.AsyncMethodAnalyzer.Analyzers.Specific.Naming
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class AsyncMethodNameSuffix_Void_Declaration_Analyzer : Abstract_Method_SymbolActionDiagnosticAnalyze
public sealed class AsyncMethodNameSuffix_Void_Declaration_Analyzer : Abstract_Method_SymbolActionDiagnosticAnalyze
{
protected override DiagnosticDescriptor DiagnosticDescriptor => MethodMissingAsyncSuffix_Void_Declaration_Rule.Rule;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System;

using MalikP.Analyzers.AsyncMethodAnalyzer.Rules.Naming;

using Microsoft.CodeAnalysis;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

using System;

using MalikP.Analyzers.AsyncMethodAnalyzer.Rules.Naming;

using Microsoft.CodeAnalysis;
Expand All @@ -35,7 +33,7 @@
namespace MalikP.Analyzers.AsyncMethodAnalyzer.Analyzers.Specific.Naming
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class CancellationTokenNameAnalyzer : AbstractSymbolActionDiagnosticAnalyzer
public sealed class CancellationTokenNameAnalyzer : AbstractSymbolActionDiagnosticAnalyzer
{
protected override DiagnosticDescriptor DiagnosticDescriptor => WrongCancellationTokenMethodParameterName_Declaration_Rule.Rule;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using System.Composition;
using System.Threading;
using System.Threading.Tasks;

using MalikP.Analyzers.AsyncMethodAnalyzer.Rules.Naming;

using Microsoft.CodeAnalysis;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected AbstractDiagnosticRuleDescriptor()
{
}

protected abstract string InternalDiagnosticId { get; }
protected abstract string publicDiagnosticId { get; }

protected abstract string Category { get; }

Expand All @@ -54,7 +54,7 @@ protected static DiagnosticDescriptor Create<T>(T diagnosticRuleDescriptor)
where T : AbstractDiagnosticRuleDescriptor
{
return new DiagnosticDescriptor(
diagnosticRuleDescriptor.InternalDiagnosticId,
diagnosticRuleDescriptor.publicDiagnosticId,
diagnosticRuleDescriptor.Title,
diagnosticRuleDescriptor.MessageFormat,
diagnosticRuleDescriptor.Category,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@

namespace MalikP.Analyzers.AsyncMethodAnalyzer.Rules.Design
{
internal sealed class CancellationTokenParameterReusePossibility_Task_Invocation_Rule : AbstractDiagnosticRuleDescriptor
public sealed class CancellationTokenParameterReusePossibility_Task_Invocation_Rule : AbstractDiagnosticRuleDescriptor
{
protected override string InternalDiagnosticId => DiagnosticId;
protected override string publicDiagnosticId => DiagnosticId;

protected override string Category => AbstractDiagnosticRuleDescriptor.Design;

Expand All @@ -53,8 +53,8 @@ private CancellationTokenParameterReusePossibility_Task_Invocation_Rule()
{
}

internal static DiagnosticDescriptor Rule { get; }
public static DiagnosticDescriptor Rule { get; }

internal static string DiagnosticId => "AADE006";
public static string DiagnosticId => "AADE006";
}
}
Loading

0 comments on commit 305a756

Please sign in to comment.