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.
FindOperationsWithNonSerializableArgumentsAnalyzerTests.cs
Go to the documentation of this file.
1using Microsoft.CodeAnalysis;
2using Microsoft.VisualStudio.TestTools.UnitTesting;
3using System;
4using System.Threading.Tasks;
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.FindOperationsWithNonSerializableArguments, diagnostic.Id,
20 nameof(DiagnosticDescriptor.Id));
21 Assert.AreEqual(FindOperationsWithNonSerializableArgumentsConstants.Title, diagnostic.Title.ToString(),
22 nameof(DiagnosticDescriptor.Title));
23 Assert.AreEqual(FindOperationsWithNonSerializableArgumentsConstants.Message, diagnostic.MessageFormat.ToString(),
24 nameof(DiagnosticDescriptor.MessageFormat));
25 Assert.AreEqual(Constants.Categories.Design, diagnostic.Category,
26 nameof(DiagnosticDescriptor.Category));
27 Assert.AreEqual(DiagnosticSeverity.Warning, diagnostic.DefaultSeverity,
28 nameof(DiagnosticDescriptor.DefaultSeverity));
29 Assert.AreEqual(HelpUrlBuilder.Build(Constants.AnalyzerIdentifiers.FindOperationsWithNonSerializableArguments, nameof(FindOperationsWithNonSerializableArgumentsAnalyzer)),
30 diagnostic.HelpLinkUri,
31 nameof(DiagnosticDescriptor.HelpLinkUri));
32 }
33
34 [TestMethod]
35 public async Task AnalyzeWithNotMobileObject()
36 {
37 var code = "public class A { }";
38 await TestHelpers.RunAnalysisAsync<FindOperationsWithNonSerializableArgumentsAnalyzer>(
39 code, Array.Empty<string>());
40 }
41
42 [TestMethod]
44 {
45 var code =
46@"using Csla;
47
48public class A : BusinessBase<A>
49{
50 public void Foo() { }
51}";
52 await TestHelpers.RunAnalysisAsync<FindOperationsWithNonSerializableArgumentsAnalyzer>(
53 code, Array.Empty<string>());
54 }
55
56 [TestMethod]
58 {
59 var code =
60@"using Csla;
61
62public class A : BusinessBase<A>
63{
64 [Fetch]
65 private void Fetch() { }
66}";
67 await TestHelpers.RunAnalysisAsync<FindOperationsWithNonSerializableArgumentsAnalyzer>(
68 code, Array.Empty<string>());
69 }
70
71 [TestMethod]
73 {
74 var code =
75@"using Csla;
76
77public class A : BusinessBase<A>
78{
79 [Fetch]
80 private void Fetch(int x) { }
81}";
82 await TestHelpers.RunAnalysisAsync<FindOperationsWithNonSerializableArgumentsAnalyzer>(
83 code, Array.Empty<string>());
84 }
85
86 [TestMethod]
88 {
89 var code =
90@"using Csla;
91
92public class A { }
93
94public class B : BusinessBase<B>
95{
96 [Fetch]
97 private void Fetch(A x) { }
98}";
99 await TestHelpers.RunAnalysisAsync<FindOperationsWithNonSerializableArgumentsAnalyzer>(
100 code, new[] { Constants.AnalyzerIdentifiers.FindOperationsWithNonSerializableArguments });
101 }
102
103 [TestMethod]
105 {
106 var code =
107@"using Csla;
108
109public class A : BusinessBase<A> { }
110
111public class B : BusinessBase<B>
112{
113 [Fetch]
114 private void Fetch(A x) { }
115}";
116 await TestHelpers.RunAnalysisAsync<FindOperationsWithNonSerializableArgumentsAnalyzer>(
117 code, Array.Empty<string>());
118 }
119
120 [TestMethod]
122 {
123 var code =
124@"using Csla;
125
126public class A { }
127
128public class B : BusinessBase<B>
129{
130 [Fetch]
131 private void Fetch([Inject] A x) { }
132}";
133 await TestHelpers.RunAnalysisAsync<FindOperationsWithNonSerializableArgumentsAnalyzer>(
134 code, Array.Empty<string>());
135 }
136
137 [TestMethod]
139 {
140 var code =
141@"using Csla;
142using System;
143
144[Serializable]
145public class A { }
146
147public class B : BusinessBase<B>
148{
149 [Fetch]
150 private void Fetch(A x) { }
151}
152";
153 await TestHelpers.RunAnalysisAsync<FindOperationsWithNonSerializableArgumentsAnalyzer>(
154 code, Array.Empty<string>());
155 }
156
157 [TestMethod]
159 {
160 var code =
161@"using Csla;
162
163public class A : BusinessBase<A>
164{
165 [FetchChild]
166 private void FetchChild() { }
167}";
168 await TestHelpers.RunAnalysisAsync<FindOperationsWithNonSerializableArgumentsAnalyzer>(
169 code, Array.Empty<string>());
170 }
171
172 [TestMethod]
174 {
175 var code =
176@"using Csla;
177
178public class A : BusinessBase<A>
179{
180 [FetchChild]
181 private void FetchChild(int x) { }
182}";
183 await TestHelpers.RunAnalysisAsync<FindOperationsWithNonSerializableArgumentsAnalyzer>(
184 code, Array.Empty<string>());
185 }
186
187 [TestMethod]
189 {
190 var code =
191@"using Csla;
192
193public class A { }
194
195public class B : BusinessBase<B>
196{
197 [FetchChild]
198 private void FetchChild(A x) { }
199}";
200 await TestHelpers.RunAnalysisAsync<FindOperationsWithNonSerializableArgumentsAnalyzer>(
201 code, Array.Empty<string>());
202 }
203 }
204}