CSLA.NET 6.0.0
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
IsCompleteCalledInAsynchronousBusinessRuleAnalyzerTests.cs
Go to the documentation of this file.
1using System;
2using System.Threading.Tasks;
3using Microsoft.CodeAnalysis;
4using Microsoft.VisualStudio.TestTools.UnitTesting;
5
7{
8 [TestClass]
10 {
11 [TestMethod]
13 {
15 var diagnostics = analyzer.SupportedDiagnostics;
16 Assert.AreEqual(1, diagnostics.Length);
17
18 var diagnostic = diagnostics[0];
19 Assert.AreEqual(Constants.AnalyzerIdentifiers.CompleteInExecuteAsync, diagnostic.Id,
20 nameof(DiagnosticDescriptor.Id));
21 Assert.AreEqual(IsCompleteCalledInAsynchronousBusinessRuleConstants.Title, diagnostic.Title.ToString(),
22 nameof(DiagnosticDescriptor.Title));
23 Assert.AreEqual(IsCompleteCalledInAsynchronousBusinessRuleConstants.Message, diagnostic.MessageFormat.ToString(),
24 nameof(DiagnosticDescriptor.MessageFormat));
25 Assert.AreEqual(Constants.Categories.Usage, diagnostic.Category,
26 nameof(DiagnosticDescriptor.Category));
27 Assert.AreEqual(DiagnosticSeverity.Error, diagnostic.DefaultSeverity,
28 nameof(DiagnosticDescriptor.DefaultSeverity));
29 Assert.AreEqual(HelpUrlBuilder.Build(Constants.AnalyzerIdentifiers.CompleteInExecuteAsync, nameof(IsCompleteCalledInAsynchronousBusinessRuleAnalyzer)),
30 diagnostic.HelpLinkUri,
31 nameof(DiagnosticDescriptor.HelpLinkUri));
32 }
33
34 [TestMethod]
36 {
37 var code = "public class A { }";
38 await TestHelpers.RunAnalysisAsync<IsCompleteCalledInAsynchronousBusinessRuleAnalyzer>(
39 code, Array.Empty<string>());
40 }
41
42 [TestMethod]
44 {
45 var code =
46@"using Csla.Rules;
47using System.Threading.Tasks;
48
49public class A : BusinessRuleAsync
50{
51 protected override Task ExecuteAsync(IRuleContext context) { }
52}";
53 await TestHelpers.RunAnalysisAsync<IsCompleteCalledInAsynchronousBusinessRuleAnalyzer>(
54 code, Array.Empty<string>());
55 }
56
57 [TestMethod]
59 {
60 var code =
61@"using Csla.Rules;
62using System.Threading.Tasks;
63
64public class A : BusinessRuleAsync
65{
66 protected override Task ExecuteAsync(IRuleContext context)
67 {
68 context.Complete();
69 }
70}";
71 await TestHelpers.RunAnalysisAsync<IsCompleteCalledInAsynchronousBusinessRuleAnalyzer>(
72 code, new[] { Constants.AnalyzerIdentifiers.CompleteInExecuteAsync });
73 }
74
75 [TestMethod]
77 {
78 var code =
79@"using Csla.Rules;
80using System.Threading.Tasks;
81
82public class A : BusinessRuleAsync
83{
84 protected override Task ExecuteAsync(IRuleContext context)
85 {
86 var c = nameof(context);
87 context.Complete();
88 }
89}";
90 await TestHelpers.RunAnalysisAsync<IsCompleteCalledInAsynchronousBusinessRuleAnalyzer>(
91 code, new[] { Constants.AnalyzerIdentifiers.CompleteInExecuteAsync });
92 }
93 }
94}