@@ -260,8 +260,80 @@ public partial class SampleViewModel : ObservableObject
260
260
261
261
test . FixedState . ExpectedDiagnostics . AddRange ( new [ ]
262
262
{
263
- // /0/Test0.cs(8,27): error CS9248: Partial property 'SampleViewModel.Name' must have an implementation part.
264
- DiagnosticResult . CompilerError ( "CS9248" ) . WithSpan ( 8 , 27 , 8 , 31 ) . WithArguments ( "MyApp.SampleViewModel.Name" ) ,
263
+ // /0/Test0.cs(8,27): error CS9248: Partial property 'SampleViewModel.FirstName' must have an implementation part.
264
+ DiagnosticResult . CompilerError ( "CS9248" ) . WithSpan ( 8 , 27 , 8 , 36 ) . WithArguments ( "MyApp.SampleViewModel.FirstName" ) ,
265
+
266
+ // /0/Test0.cs(11,27): error CS9248: Partial property 'SampleViewModel.LastName' must have an implementation part.
267
+ DiagnosticResult . CompilerError ( "CS9248" ) . WithSpan ( 11 , 27 , 11 , 35 ) . WithArguments ( "MyApp.SampleViewModel.LastName" ) ,
268
+ } ) ;
269
+
270
+ await test . RunAsync ( ) ;
271
+ }
272
+
273
+ [ TestMethod ]
274
+ public async Task SimpleProperty_Multiple_OnlyTriggersOnFirstOne ( )
275
+ {
276
+ string original = """
277
+ using CommunityToolkit.Mvvm.ComponentModel;
278
+
279
+ namespace MyApp;
280
+
281
+ public class SampleViewModel : ObservableObject
282
+ {
283
+ public string FirstName
284
+ {
285
+ get => field;
286
+ set => SetProperty(ref field, value);
287
+ }
288
+
289
+ private string _lastName;
290
+
291
+ public string LastName
292
+ {
293
+ get => _lastName;
294
+ set => SetProperty(ref _lastName, value);
295
+ }
296
+ }
297
+ """ ;
298
+
299
+ string @fixed = """
300
+ using CommunityToolkit.Mvvm.ComponentModel;
301
+
302
+ namespace MyApp;
303
+
304
+ public partial class SampleViewModel : ObservableObject
305
+ {
306
+ [ObservableProperty]
307
+ public partial string FirstName { get; set; }
308
+
309
+ private string _lastName;
310
+
311
+ public string LastName
312
+ {
313
+ get => _lastName;
314
+ set => SetProperty(ref _lastName, value);
315
+ }
316
+ }
317
+ """ ;
318
+
319
+ CSharpCodeFixTest test = new ( LanguageVersion . Preview )
320
+ {
321
+ TestCode = original ,
322
+ FixedCode = @fixed ,
323
+ ReferenceAssemblies = ReferenceAssemblies . Net . Net80 ,
324
+ } ;
325
+
326
+ test . TestState . AdditionalReferences . Add ( typeof ( ObservableObject ) . Assembly ) ;
327
+ test . ExpectedDiagnostics . AddRange ( new [ ]
328
+ {
329
+ // /0/Test0.cs(7,19): info MVVMTK0056: The semi-auto property MyApp.SampleViewModel.FirstName can be converted to a partial property using [ObservableProperty], which is recommended (doing so makes the code less verbose and results in more optimized code)
330
+ CSharpCodeFixVerifier . Diagnostic ( ) . WithSpan ( 7 , 19 , 7 , 28 ) . WithArguments ( "MyApp.SampleViewModel" , "FirstName" ) ,
331
+ } ) ;
332
+
333
+ test . FixedState . ExpectedDiagnostics . AddRange ( new [ ]
334
+ {
335
+ // /0/Test0.cs(8,27): error CS9248: Partial property 'SampleViewModel.FirstName' must have an implementation part.
336
+ DiagnosticResult . CompilerError ( "CS9248" ) . WithSpan ( 8 , 27 , 8 , 36 ) . WithArguments ( "MyApp.SampleViewModel.FirstName" ) ,
265
337
} ) ;
266
338
267
339
await test . RunAsync ( ) ;
@@ -447,8 +519,11 @@ public partial class SampleViewModel : ObservableObject
447
519
448
520
test . FixedState . ExpectedDiagnostics . AddRange ( new [ ]
449
521
{
450
- // /0/Test0.cs(8,27): error CS9248: Partial property 'SampleViewModel.Name' must have an implementation part.
451
- DiagnosticResult . CompilerError ( "CS9248" ) . WithSpan ( 8 , 27 , 8 , 31 ) . WithArguments ( "MyApp.SampleViewModel.Name" ) ,
522
+ // /0/Test0.cs(8,27): error CS9248: Partial property 'SampleViewModel.FirstName' must have an implementation part.
523
+ DiagnosticResult . CompilerError ( "CS9248" ) . WithSpan ( 8 , 27 , 8 , 36 ) . WithArguments ( "MyApp.SampleViewModel.FirstName" ) ,
524
+
525
+ // /0/Test0.cs(11,27): error CS9248: Partial property 'SampleViewModel.LastName' must have an implementation part.
526
+ DiagnosticResult . CompilerError ( "CS9248" ) . WithSpan ( 11 , 27 , 11 , 35 ) . WithArguments ( "MyApp.SampleViewModel.LastName" ) ,
452
527
} ) ;
453
528
454
529
await test . RunAsync ( ) ;
@@ -616,6 +691,12 @@ public class TestAttribute(string text) : Attribute;
616
691
617
692
// /0/Test0.cs(32,27): error CS9248: Partial property 'SampleViewModel.Prop5' must have an implementation part.
618
693
DiagnosticResult . CompilerError ( "CS9248" ) . WithSpan ( 32 , 27 , 32 , 32 ) . WithArguments ( "MyApp.SampleViewModel.Prop5" ) ,
694
+
695
+ // /0/Test0.cs(36,27): error CS9248: Partial property 'SampleViewModel.Prop6' must have an implementation part.
696
+ DiagnosticResult . CompilerError ( "CS9248" ) . WithSpan ( 36 , 27 , 36 , 32 ) . WithArguments ( "MyApp.SampleViewModel.Prop6" ) ,
697
+
698
+ // /0/Test0.cs(39,27): error CS9248: Partial property 'SampleViewModel.Prop7' must have an implementation part.
699
+ DiagnosticResult . CompilerError ( "CS9248" ) . WithSpan ( 39 , 27 , 39 , 32 ) . WithArguments ( "MyApp.SampleViewModel.Prop7" ) ,
619
700
} ) ;
620
701
621
702
await test . RunAsync ( ) ;
0 commit comments