@@ -19,6 +19,7 @@ namespace ConsoleApplication1
19
19
class TestComponent : IComponent
20
20
{{
21
21
[Parameter] public string TestProperty {{ get; set; }}
22
+ [Parameter] public int TestInt {{ get; set; }}
22
23
public string NonParameter {{ get; set; }}
23
24
}}
24
25
}}" + ComponentsTestDeclarations . Source ;
@@ -119,6 +120,68 @@ void Render()
119
120
} ) ;
120
121
}
121
122
123
+ [ Fact ]
124
+ public void ComponentPropertyIncrement_Warns ( )
125
+ {
126
+ var test = $@ "
127
+ namespace ConsoleApplication1
128
+ {{
129
+ using { typeof ( ParameterAttribute ) . Namespace } ;
130
+ class OtherComponent : IComponent
131
+ {{
132
+ private TestComponent _testComponent;
133
+ void Render()
134
+ {{
135
+ _testComponent = new TestComponent();
136
+ _testComponent.TestInt++;
137
+ }}
138
+ }}
139
+ }}" + ComponentTestSource ;
140
+
141
+ VerifyCSharpDiagnostic ( test ,
142
+ new DiagnosticResult
143
+ {
144
+ Id = DiagnosticDescriptors . ComponentParametersShouldNotBeSetOutsideOfTheirDeclaredComponent . Id ,
145
+ Message = "Component parameter 'TestInt' should not be set outside of its component." ,
146
+ Severity = DiagnosticSeverity . Warning ,
147
+ Locations = new [ ]
148
+ {
149
+ new DiagnosticResultLocation ( "Test0.cs" , 11 , 17 )
150
+ }
151
+ } ) ;
152
+ }
153
+
154
+ [ Fact ]
155
+ public void ComponentPropertyDecrement_Warns ( )
156
+ {
157
+ var test = $@ "
158
+ namespace ConsoleApplication1
159
+ {{
160
+ using { typeof ( ParameterAttribute ) . Namespace } ;
161
+ class OtherComponent : IComponent
162
+ {{
163
+ private TestComponent _testComponent;
164
+ void Render()
165
+ {{
166
+ _testComponent = new TestComponent();
167
+ _testComponent.TestInt--;
168
+ }}
169
+ }}
170
+ }}" + ComponentTestSource ;
171
+
172
+ VerifyCSharpDiagnostic ( test ,
173
+ new DiagnosticResult
174
+ {
175
+ Id = DiagnosticDescriptors . ComponentParametersShouldNotBeSetOutsideOfTheirDeclaredComponent . Id ,
176
+ Message = "Component parameter 'TestInt' should not be set outside of its component." ,
177
+ Severity = DiagnosticSeverity . Warning ,
178
+ Locations = new [ ]
179
+ {
180
+ new DiagnosticResultLocation ( "Test0.cs" , 11 , 17 )
181
+ }
182
+ } ) ;
183
+ }
184
+
122
185
[ Fact ]
123
186
public void ComponentPropertyExpression_Ignores ( )
124
187
{
0 commit comments