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.
IsOperationMethodPublicAnalyzerTests.cs
Go to the documentation of this file.
1using Microsoft.CodeAnalysis;
2using Microsoft.VisualStudio.TestTools.UnitTesting;
3using System;
4using System.Linq;
5using System.Threading.Tasks;
6
8{
9 [TestClass]
11 {
12 [TestMethod]
14 {
15 var analyzer = new IsOperationMethodPublicAnalyzer();
16 var diagnostics = analyzer.SupportedDiagnostics;
17 Assert.AreEqual(2, diagnostics.Length);
18
19 var diagnostic = diagnostics.Single(_ => _.Id == Constants.AnalyzerIdentifiers.IsOperationMethodPublic);
20 Assert.AreEqual(IsOperationMethodPublicAnalyzerConstants.Title, diagnostic.Title.ToString(),
21 nameof(DiagnosticDescriptor.Title));
22 Assert.AreEqual(IsOperationMethodPublicAnalyzerConstants.Message, diagnostic.MessageFormat.ToString(),
23 nameof(DiagnosticDescriptor.MessageFormat));
24 Assert.AreEqual(Constants.Categories.Design, diagnostic.Category,
25 nameof(DiagnosticDescriptor.Category));
26 Assert.AreEqual(DiagnosticSeverity.Warning, diagnostic.DefaultSeverity,
27 nameof(DiagnosticDescriptor.DefaultSeverity));
28 Assert.AreEqual(HelpUrlBuilder.Build(Constants.AnalyzerIdentifiers.IsOperationMethodPublic, nameof(IsOperationMethodPublicAnalyzer)),
29 diagnostic.HelpLinkUri,
30 nameof(DiagnosticDescriptor.HelpLinkUri));
31
32 var diagnosticForInterface = diagnostics.Single(_ => _.Id == Constants.AnalyzerIdentifiers.IsOperationMethodPublicForInterface);
33 Assert.AreEqual(IsOperationMethodPublicAnalyzerConstants.Title, diagnosticForInterface.Title.ToString(),
34 nameof(DiagnosticDescriptor.Title));
35 Assert.AreEqual(IsOperationMethodPublicAnalyzerConstants.Message, diagnosticForInterface.MessageFormat.ToString(),
36 nameof(DiagnosticDescriptor.MessageFormat));
37 Assert.AreEqual(Constants.Categories.Design, diagnosticForInterface.Category,
38 nameof(DiagnosticDescriptor.Category));
39 Assert.AreEqual(DiagnosticSeverity.Warning, diagnosticForInterface.DefaultSeverity,
40 nameof(DiagnosticDescriptor.DefaultSeverity));
41 Assert.AreEqual(HelpUrlBuilder.Build(Constants.AnalyzerIdentifiers.IsOperationMethodPublicForInterface, nameof(IsOperationMethodPublicAnalyzer)),
42 diagnosticForInterface.HelpLinkUri,
43 nameof(DiagnosticDescriptor.HelpLinkUri));
44 }
45
46 [TestMethod]
48 {
49 var code =
50@"public class A
51{
52 [Fetch]
53 public void Fetch() { }
54}";
55 await TestHelpers.RunAnalysisAsync<IsOperationMethodPublicAnalyzer>(
56 code, Array.Empty<string>());
57 }
58
59 [TestMethod]
61 {
62 var code =
63@"using Csla;
64using System;
65
66[Serializable]
67public class A : BusinessBase<A>
68{
69 public void AMethod() { }
70}";
71 await TestHelpers.RunAnalysisAsync<IsOperationMethodPublicAnalyzer>(
72 code, Array.Empty<string>());
73 }
74
75 [TestMethod]
77 {
78 var code =
79@"using Csla;
80using System;
81
82[Serializable]
83public class A : BusinessBase<A>
84{
85 private void DataPortal_Fetch() { }
86}";
87 await TestHelpers.RunAnalysisAsync<IsOperationMethodPublicAnalyzer>(
88 code, Array.Empty<string>());
89 }
90
91 [TestMethod]
93 {
94 var code =
95@"using Csla;
96using System;
97
98[Serializable]
99public class A : BusinessBase<A>
100{
101 [Fetch]
102 public void Fetch() { }
103}";
104 await TestHelpers.RunAnalysisAsync<IsOperationMethodPublicAnalyzer>(code,
105 new[] { Constants.AnalyzerIdentifiers.IsOperationMethodPublic },
106 diagnostics => Assert.AreEqual(false.ToString(), diagnostics[0].Properties[IsOperationMethodPublicAnalyzerConstants.IsSealed]));
107 }
108
109 [TestMethod]
111 {
112 var code =
113@"using Csla;
114using System;
115
116[Serializable]
117public sealed class A : BusinessBase<A>
118{
119 [Fetch]
120 public void Fetch() { }
121}";
122 await TestHelpers.RunAnalysisAsync<IsOperationMethodPublicAnalyzer>(code,
123 new[] { Constants.AnalyzerIdentifiers.IsOperationMethodPublic },
124 diagnostics => Assert.AreEqual(true.ToString(), diagnostics[0].Properties[IsOperationMethodPublicAnalyzerConstants.IsSealed]));
125 }
126
127 [TestMethod]
129 {
130 var code =
131@"using Csla;
132using Csla.Core;
133
134public interface A
135 : IBusinessObject
136{
137 [Fetch]
138 void Fetch();
139}";
140 await TestHelpers.RunAnalysisAsync<IsOperationMethodPublicAnalyzer>(code,
141 new[] { Constants.AnalyzerIdentifiers.IsOperationMethodPublicForInterface });
142 }
143 }
144}