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.
DoesOperationHaveAttributeAnalyzerTests.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 {
14 var analyzer = new DoesOperationHaveAttributeAnalyzer();
15 var diagnostics = analyzer.SupportedDiagnostics;
16 Assert.AreEqual(1, diagnostics.Length);
17
18 var diagnostic = diagnostics[0];
19 Assert.AreEqual(Constants.AnalyzerIdentifiers.DoesOperationHaveAttribute, diagnostic.Id,
20 nameof(DiagnosticDescriptor.Id));
21 Assert.AreEqual(DoesOperationHaveAttributeAnalyzerConstants.Title, diagnostic.Title.ToString(),
22 nameof(DiagnosticDescriptor.Title));
23 Assert.AreEqual(DoesOperationHaveAttributeAnalyzerConstants.Message, diagnostic.MessageFormat.ToString(),
24 nameof(DiagnosticDescriptor.MessageFormat));
25 Assert.AreEqual(Constants.Categories.Usage, diagnostic.Category,
26 nameof(DiagnosticDescriptor.Category));
27 Assert.AreEqual(DiagnosticSeverity.Info, diagnostic.DefaultSeverity,
28 nameof(DiagnosticDescriptor.DefaultSeverity));
29 Assert.AreEqual(HelpUrlBuilder.Build(Constants.AnalyzerIdentifiers.DoesOperationHaveAttribute, nameof(DoesOperationHaveAttributeAnalyzer)),
30 diagnostic.HelpLinkUri,
31 nameof(DiagnosticDescriptor.HelpLinkUri));
32 }
33
34 [TestMethod]
36 {
37 var code = "public class A { }";
38 await TestHelpers.RunAnalysisAsync<DoesOperationHaveAttributeAnalyzer>(
39 code, Array.Empty<string>());
40 }
41
42 [TestMethod]
44 {
45 var code =
46@"using Csla;
47
48public class A : BusinessBase<A>
49{
50 [Fetch]
51 private void DataPortal_Fetch() { }
52}";
53 await TestHelpers.RunAnalysisAsync<DoesOperationHaveAttributeAnalyzer>(
54 code, Array.Empty<string>());
55 }
56
57 [TestMethod]
59 {
60 var code =
61@"using Csla;
62
63public class A : BusinessBase<A>
64{
65 [Fetch]
66 private void Fetch() { }
67}";
68 await TestHelpers.RunAnalysisAsync<DoesOperationHaveAttributeAnalyzer>(
69 code, Array.Empty<string>());
70 }
71
72 [TestMethod]
74 {
75 var code =
76@"using Csla;
77
78public class A : BusinessBase<A>
79{
80 private void DataPortal_Fetch() { }
81}";
82 await TestHelpers.RunAnalysisAsync<DoesOperationHaveAttributeAnalyzer>(
83 code, new[] { Constants.AnalyzerIdentifiers.DoesOperationHaveAttribute });
84 }
85 }
86}